C# winform 选择文件保存路径
1、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; }