使用OpenFileDialog打开文件和使用FolderBrowserDialog选定文件夹

选定文件夹
string foldPath = ""; FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择文件路径"; dialog.SelectedPath = ""; //dialog.RootFolder = Environment.SpecialFolder.Programs; if (dialog.ShowDialog() == DialogResult.OK) { foldPath = dialog.SelectedPath; } else { return; }

打开文件

		OpenFileDialog openFileDialog1 = new OpenFileDialog();
		string File_Name = "";
		openFileDialog1.Filter = "所有文件(*.*)|*.*";
		if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
		{
			File_Name = openFileDialog1.FileName;

		}
		else
		{
			return;
		}

`

原文地址:https://www.cnblogs.com/dengzhekaihua/p/15524270.html