关于WPF中openfiledialog文件多选
展开全部
详见代码和注释:
System.Windows.Forms.OpenFileDialog openFile = new System.Windows.Forms.OpenFileDialog();
openFile.CheckFileExists = true;//检查文件是否存在
openFile.CheckPathExists = true;//检查路径是否存在
openFile.Multiselect = true;//是否允许多选,false表示单选
openFile.InitialDirectory = "C:\\";//设置打开时的默认路径,我这里设置为C盘根目录
string filter = "txt,doc";
filter = filter.TrimEnd(',');
if (filter.Equals(""))
{
filter = "*";
}
filter = filter.Replace(",", ";*.");
filter = "*." + filter;
openFile.Filter = "Txt files (" + filter + ")|" + filter + "|All files (*.*)|*.*";//这里设置的是文件过滤器,比如选了txt文件,那别的文件就看不到了
if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)//打开文件选择器,并按下选择按钮
{
String[] names = openFile.FileNames;
String message = "已选择的文件如下:\r\n";
for (int i = 0; i < names.length; i++)
{
message += names + "\r\n";
}
MessageBox.show(message);
}
另外,你说不能多选,这个多选时要按住Ctrl才能选中多个文件,或者按住鼠标左键滑动以选定多个目标才行。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询