C# 选择文件 选择文件夹
程序员文章站
2022-06-08 22:24:50
...
C# 选择文件 选择文件夹
//选择文件夹
private String selectFolder()
{
String path = "";
System.Windows.Forms.FolderBrowserDialog folderChooser = new System.Windows.Forms.FolderBrowserDialog();
folderChooser.Description = "请选择文件夹";
if (folderChooser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
path = folderChooser.SelectedPath;
}
return path;
}
//选择文件
private String selectFile()
{
String path = "";
System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog();
//设置是否可以多选
fileDialog.Multiselect = true;
//设置标题
fileDialog.Title = "请选择文件";
//设置初始打开目录,默认为空
fileDialog.InitialDirectory = "";
//设置文件过滤,不同格式用分号隔开
fileDialog.Filter = "文本1(*.txt)|*.txt;*.py|文本2(*.csv)|*.csv";
if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
path = fileDialog.FileName;
//获取多个文件路径
String[] paths = fileDialog.FileNames;
}
return path;
}
上一篇: Android 浅谈MVP模式 一
下一篇: Git初步入门(五)标签的操作