c#_winform_选择文件保存路径

1、winform 点击按钮选择文件保存的路径,效果如下图:

《c#_winform_选择文件保存路径》

 

具体代码如下:

 

     private void button8_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.Description = "请选择文件路径";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string foldPath = dialog.SelectedPath;
                DirectoryInfo theFolder = new DirectoryInfo(foldPath);
                
                //theFolder 包含文件路径

                FileInfo[] dirInfo = theFolder.GetFiles();
                //遍历文件夹                
                foreach (FileInfo file in dirInfo)
                {
                    MessageBox.Show(file.ToString());
                }
            }
        }

 

 

winform 打开指定的文件夹

 System.Diagnostics.Process.Start("路径");

 

2、winform 打开指定文件,精确到文件

 

OpenFileDialog dialog = new OpenFileDialog();
dialog.Multiselect = true;//该值确定是否可以选择多个文件
dialog.Title = "请选择文件夹";
dialog.Filter = "所有文件(*.*)|*.*";
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    string file = dialog.FileName;
}

 

    原文作者:x1angzeeD.
    原文地址: https://blog.csdn.net/qq_48705696/article/details/110629537
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞