如何知道c#中opendialog中有多少选定文件?
如何知道在c#中的opendialog中选择了多少个文件?。文件名可能会包含所选项目的计数:) 获取对话框中所有选定文件的文件名 比如说如何知道c#中opendialog中有多少选定文件?,c#,file,multi-select,opendialog,C#,File,Multi Select,Opendialog,如何知道在c#中的opendialog中选择了多少个文件?。文件名可能会包含所选项目的计数:) 获取对话框中所有选定文件的文件名 比如说 foreach (String myfile in openFileDialog1.FileNames) { // here myfile represent your selected file name } 在WinForms中,检查OpenFileDialogsFileNames属性,该属性将保存所有选定的文件。在WPF中,使用文件属性。私有v
foreach (String myfile in openFileDialog1.FileNames)
{
// here myfile represent your selected file name
}
在WinForms中,检查OpenFileDialogs
FileNames
属性,该属性将保存所有选定的文件。在WPF中,使用文件属性。私有void openFileDialog1\u FileOk(对象发送方,取消事件参数e)
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
openFileDialog1.Multiselect = true;
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
List<string> fff = openFileDialog1.FileNames.ToList();
// Do something with the list
}
}
{
openFileDialog1.Multiselect=true;
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{
DialogResult=openFileDialog1.ShowDialog();
if(result==DialogResult.OK)
{
List fff=openFileDialog1.FileNames.ToList();
//对清单做点什么
}
}
Thsi将获取文件夹中的文件数,而不是用户选择的文件数。如果使用FolderBrowserDialog,则此功能有效。如果您使用OpenFileDialog,您可以获得带有op.filenames的文件。添加一些解释,说明此答案如何帮助op解决当前问题“使用列表做些什么”,例如int X=fff.Count,它给出OpenFileDialog中所选文件的数量。
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
openFileDialog1.Multiselect = true;
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
List<string> fff = openFileDialog1.FileNames.ToList();
// Do something with the list
}
}