使用OpenFileDialog选择文件
来源:互联网 发布:网络制式有哪些 编辑:程序博客网 时间:2024/05/11 11:20
/// <summary>
/// 浏览文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnOpenFileDialog_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.RestoreDirectory = true;
ofd.Title = "打开(Open)";
ofd.FileName = "";
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);//为了获取特定的系统文件夹,可以使用System.Environment类的静态方法GetFolderPath()。该方法接受一个Environment.SpecialFolder枚举,其中可以定义要返回路径的哪个系统目录
ofd.Filter = "文本文件(*.txt)|*.txt";
ofd.ValidateNames = true; //文件有效性验证ValidateNames,验证用户输入是否是一个有效的Windows文件名
ofd.CheckFileExists = true; //验证路径有效性
ofd.CheckPathExists = true; //验证文件有效性
try
{
if (ofd.ShowDialog() == DialogResult.OK)
{
string fileNamePath = ofd.FileName;
this.txtFileName.Text = fileNamePath;
btnDownLoadBySelectFile.Enabled = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
- 使用OpenFileDialog选择文件
- 使用OpenFileDialog 控件添加文件
- 用openFileDialog选择多个文件
- 文件选择框类 OpenFileDialog类
- 文件选择对话框filedialog,OpenFileDialog,FolderBrowserDialog
- Unity3d调用system.windows.forms.dll使用OpenFileDialog打开文件选择窗口
- Windows的OpenFileDialog双击文件选择时,系统crash
- 【C#】文件选择对话框OpenFileDialog与下列列表ComboBox
- 使用矩阵方式进行文件夹的选择即类似OpenFileDialog
- C# FolderBrowserDialog和OpenFileDialog 使用 指定目录和指定文件
- vb.net 的 openFileDialog 控件文件筛选器使用
- openfiledialog 使用 读取txt文件 StreamReader 检验数据
- c#openFileDialog读取文件
- OpenFileDialog多选多个文件
- 打开文件对话框OpenFileDialog
- OpenFileDialog()打开指定文件
- openFileDialog选择图片放进pictureBox
- unity----OpenFileDialog打开选择对话框
- 遍历目标文件夹下所有文件
- linux关机和重启命令
- 按值传递还是按引用传递
- 没牛逼以前还是老老实实的吧。
- 大象--Thinking in UML早知道 -- 002--面向过程方法与面向对象方法
- 使用OpenFileDialog选择文件
- 特殊SQL语句及优化原则
- 大象--Thinking in UML早知道 -- 003--基本建模方法
- ASC码对照表
- 大象--Thinking in UML早知道 -- 004--参与者基本概念
- [转帖]关于如何在matlab中添加新的工具箱的整理和心得
- 大象--Thinking in UML早知道 -- 005--业务实体
- python中try结构中变量的作用域
- 有关 list 内存释放的小技巧