OpenFileDialog的基本操作

来源:互联网 发布:interlagos羽绒被 知乎 编辑:程序博客网 时间:2024/06/05 09:16



一.获取文件名和文件路径问题

System.IO.Path.GetFullPath(openFileDialog.FileName);                              //绝对路径

System.IO.Path.GetExtension(openFileDialog.FileName);                           //文件扩展名

System.IO.Path.GetFileNameWithoutExtension(openFileDialog.FileName); //文件名没有扩展名

System.IO.Path.GetFileName(openFileDialog.FileName);                           //得到文件

System.IO.Path.GetDirectoryName(openFileDialog.FileName);                  //得到路径


二.如何弹出文件选择对话框

 var openFileDialog = new Microsoft.Win32.OpenFileDialog()
            {

//设置文件的后缀名
                Filter = "文本文件(*.txt)|*.txt|Excel (*.xls 或 *.xlsx)|*.xls;*.xlsx|access (*.mdb 或 *.accdb)|*.mdb;*.accdb||"
            };
            var result = openFileDialog.ShowDialog();
            if (result == true)
            {
               //todo 选择文件后的逻辑
               //获取该文件的绝对路径
              string  strPath=importData.filePath = openFileDialog.FileName;
    
            }

1 0
原创粉丝点击