WPF 打开一个或多个文件(可按住Ctrl键进行多选)
private string[] GetFiles() { string[] files = null; OpenFileDialog dlg = new OpenFileDialog(); dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); dlg.Multiselect = true; //dlg.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; //dlg.FilterIndex = 2; //dlg.RestoreDirectory = true; if (dlg.ShowDialog() == true) files = dlg.FileNames; return files; }
dlg.Multiselect = true;//设置是否可以多选