OpenFileDialog openFileDialog = new OpenFileDialog();
//打开的文件选择对话框上的标题
openFileDialog.Title = "请选择文件";
//设置文件类型
openFileDialog.Filter = "文本文件(*.txt)|*.txt|全部文件(*.*)|*.*";
//设置默认文件类型显示顺序
openFileDialog.FilterIndex = 1;
//保存对话框是否记忆上次打开的文件夹
openFileDialog.RestoreDirectory = true;
//设置是否同意多选
openFileDialog.Multiselect = false;
//按下确定选择的button
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//获得文件路径
string localFilePath = openFileDialog.FileName.ToString();
//获取文件路径。不带文件名称
//FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
//获取文件名称。带后缀名,不带路径
string fileNameWithSuffix = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);
//去除文件后缀名
string fileNameWithoutSuffix = fileNameWithSuffix.Substring(0, fileNameWithSuffix.LastIndexOf("."));
//在文件名称前加上时间
string fileNameWithTime = DateTime.Now.ToString("yyyy-MM-dd ") + fileNameExt;
//在文件名称里加字符
string newFileName = localFilePath.Insert(1, "dameng");
}

本文固定链接:http://www.itechzero.com/c-sharp-openfiledialog-usage.html。转载请注明出处。

最新文章

  1. 基于jPlayer的三分屏制作
  2. RelativeLayout实现左中右布局
  3. ios cocos2d TexturePacker生成文件后的使用方法
  4. 用 vs2013 创建 windows service 程序
  5. Lists
  6. Linux下的crontab定时执行任务命令详解
  7. HDU 5755 Gambler Bo
  8. Unity3d导出Recast geomset.txt
  9. Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.4.1:clean (default-clean) on project
  10. 关于linux - Centos 7 系统下使用PXE网络的方式(pxe+dhcpd+tftp+httpd)安装操作系统
  11. box-sizing的用法
  12. Spring controller 中接收JSON参数失败
  13. 【微服务】.netCore eShopOnContainers 部署实践《二》
  14. Android Studio 编译: Program type already present: XXX 解决方案
  15. 解决IE兼容模式的方案
  16. android将应用中图片保存到系统相册并显示
  17. scp 链接文件的问题 + tar
  18. cmd 命令阻塞继续执行下面的命令的办法
  19. 如何开启apache的PHP-FPM实例
  20. 【20181023T1】战争【反向并查集】

热门文章

  1. linux 查看java进程
  2. edmx-新建表
  3. 经典Mathematica函数大全
  4. Attention Mechanism
  5. Jmeter接口测试系列之参数化方法
  6. MFC自绘框架窗口客户区
  7. mfc小工具开发之定时闹钟之---多线程急线程同步
  8. mysql快速上手
  9. ubuntu安装jdk详细教程
  10. spark(1.1) mllib 源码分析(一)-卡方检验