OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "选择导入的文件";
ofd.FilterIndex = 1;
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);//为了获取特定的系统文件夹,可以使用System.Environment类的静态方法GetFolderPath()。该方法接受一个Environment.SpecialFolder枚举,其中可以定义要返回路径的哪个系统目录
ofd.Filter = "Excel文件(*.xls)|*.xls";
ofd.ValidateNames = true; //文件有效性验证ValidateNames,验证用户输入是否是一个有效的Windows文件名
ofd.CheckFileExists = true; //验证路径有效性
ofd.CheckPathExists = true; //验证文件有效性
if (ofd.ShowDialog() == DialogResult.OK)

OpenFileDialog 打开文件的更多相关文章

  1. WPF - 使用Microsoft.Win32.OpenFileDialog打开文件,使用Microsoft.Win32.SaveFileDialog将文件另存

    1. WPF 使用这个方法打开文件,很方便,而且可以记住上次打开的路径. Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.W ...

  2. C# OpenFileDialog打开文件对话框(详解)

    一.打开文件对话框(OpenFileDialog) 1. OpenFileDialog控件的基本属性 InitialDirectory:对话框的初始目录 Filter: 获取或设置当前文件名筛选器字符 ...

  3. 使用OpenFileDialog打开文件和使用FolderBrowserDialog选定文件夹

    选定文件夹 string foldPath = ""; FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog ...

  4. OpenFileDialog 打开文件对话框

    InitialDirectory 对话框的初始目录 Filter 要在对话框中显示的文件筛选器,例如,"文本文件(*.txt)|*.txt|所有文件(*.*)||*.*" Filt ...

  5. WPF中使用OpenFileDialog打开文件

    添加Microsoft.Win32程序集 private void OnOpenFile(object sender, EventArgs e) { OpenFileDialog openFileDi ...

  6. C#选择文件、选择文件夹、打开文件

    1.选择文件用OpenDialog OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = true;//该值确定是否可以 ...

  7. C# winform选择文件、选择文件夹、打开文件

    文章来自博客园友,这里只是做一下笔记. 来源:https://www.cnblogs.com/liuqifeng/p/9149125.html 一.选择文件用OpenDialog OpenFileDi ...

  8. OpenFileDialog组件打开文件....待续

    1.常用属性 InitialDirectory           对话框的初始目录 this.openFileDialog1.InitialDirectory = "d:\\"; ...

  9. Winform控件:打开文件对话框(OpenFileDialog)

    OpenFileDialog类提供了用户打开文件的功能,它有如下属性: 属性 InitialDirectory:设置对话框的初始目录. Filter: 要在对话框中显示的文件筛选器,例如," ...

随机推荐

  1. HDUOJ----4006The kth great number(最小堆...)

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  2. poj-------Common Subsequence(poj 1458)

    Common Subsequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 34477   Accepted: 13 ...

  3. pip安装注意事项

    pip源 清华:https://pypi.tuna.tsinghua.edu.cn/simple 阿里云:http://mirrors.aliyun.com/pypi/simple/ 中国科技大学 h ...

  4. log4j的NDC/MDC区别与应用

    MDC与NDC除了存储方式(MDC采用MapNDC采用堆栈结构)有区别,其他都一样的 关键点 A -//引入log4j MDC类org.apache.log4j.MDC -//设置值 -MDC.put ...

  5. iOS - Contacts 通讯录

    Contacts 通讯录 1.访问通讯录 设置系统访问通讯录权限 1.1 iOS 9.0 及 iOS 9.0 之后获取通讯录的方法 iOS 9.0 及 iOS 9.0 之后获取通讯录的方法 // 包含 ...

  6. 下载url地址的图片

    // string url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=cNaaMfvhpb1vmcVRXRAdI ...

  7. Python radians() 函数

    描述 radians() 方法将角度转换为弧度. 语法 以下是 radians() 方法的语法: import math math.radians(x) 注意:radians()是不能直接访问的,需要 ...

  8. Note for video Machine Learning and Data Mining——training vs Testing

    Here is the note for lecture five. There will be several points  1. Training and Testing  Both of th ...

  9. HTML - 隐藏滚动条但可以滚动

    代码:(原理就是遮盖) 1.如果你把子div的140px宽度移除,你就明白其中的奥妙了. 2.原理就是父元素负责滚动,子元素负责遮盖. <html> <style> .scro ...

  10. java web中jsp常用标签

    在jsp页面开发过程中,经常需要使用JSTL(Java Server Pages Standard Tag Library)标签开开发页面,是看起来更加的规整舒服. JSTL主要提供了5大类标签库: ...