- //选择文件夹
- FolderBrowserDialog dia = new FolderBrowserDialog();
- if (dia.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- string filePath = dia.SelectedPath;
- Directory.Exists(filePath);//判断文件夹是否存在
- }
- //选择文件
- OpenFileDialog dia = new OpenFileDialog();
- if (dia.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- string filePath = dia.SelectedPath;
- File.Exists(filePath);//判断文件是否存在
- }
转载于:https://www.cnblogs.com/shenbing/p/5986734.html
本文介绍如何使用C#的FolderBrowserDialog和OpenFileDialog组件来让用户选择文件夹和文件。通过实例展示了如何获取用户选择的路径,并检查所选文件夹或文件是否存在的方法。
918

被折叠的 条评论
为什么被折叠?



