C#选择文件(OpenFileDialog)、选择文件夹(FolderBrowserDialog)

2021-03-18 11:24

阅读:690

标签:扩展名   get   文件   san   12px   size   extension   filedia   str   

1  选择文件(OpenFileDialog

            OpenFileDialog dialog = new OpenFileDialog();
            //dialog.Multiselect = true;//该值确定是否可以选择多个文件
           // dialog.Title = "请选择文件";
            //dialog.Filter = "所有文件(*.*)|*.*";
            //dialog.InitialDirectory = @"E:\";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string fullFileName = dialog.FileName;// @"e:\日记.doc";
                //var FileName =System.IO.Path.GetFileName(fullFileName); //文件名  “日记.doc”
                //string extension = System.IO.Path.GetExtension(fullFileName);//扩展名 “.doc”
                //string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fullFileName);// 没有扩展名的文件名 “日记”

            }

2  选择文件夹(System.Windows.Forms.FolderBrowserDialog)

            System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
            dialog.Description = "请选择Txt所在文件夹";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {               string path = dialog.SelectedPath; // "e:/go"
            }

 

C#选择文件(OpenFileDialog)、选择文件夹(FolderBrowserDialog)

标签:扩展名   get   文件   san   12px   size   extension   filedia   str   

原文地址:https://www.cnblogs.com/pu369/p/12358284.html


评论


亲,登录后才可以留言!