我想要实现的是从OpenFileDialog中选择多个文件夹和文件同时。
建议的解决方案:
OpenFileDialog.Multiselect = true;
OpenFileDialog.ValidateNames = false;
OpenFileDialog.CheckFileExists = false;
OpenFileDialog.CheckPathExists = true;
OpenFileDialog.FileName = "Dummy";
OpenFileDialog.Filter = string.Empty;
当用户选择文件夹和文件同时时,此设置无效。
我正在寻找一个解决方案,当用户按下打开按钮并获取所选文件和文件夹的路径时,我可以通过该解决方案关闭对话框。
答案 0 :(得分:0)
我认为这个问题已经回答here
我会重复一遍:
如果使用FileNames属性而不是FileName属性,则会获得每个文件的字符串数组,您可以使用shift键选择多个文件。像这样:
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog x = new OpenFileDialog();
x.Multiselect = true;
x.ShowDialog();
string[] result = x.FileNames;
foreach (string y in result)
MessageBox.Show(y, "Selected Item", MessageBoxButtons.OK, MessageBoxIcon.Information);
}