【问题标题】:How to know how many selected files in opendialog in c#?c#如何知道opendialog中有多少选定的文件?
【发布时间】:2012-05-26 23:45:10
【问题描述】:

c#如何知道opendialog中选择了多少个文件?

【问题讨论】:

    标签: c# file multi-select opendialog


    【解决方案1】:

    .FileNames 可能会保存所选项目的数量:)

    【讨论】:

      【解决方案2】:

      FileDialog.FileNames Property

      获取对话框中所有选定文件的文件名。

      例如

      foreach (String myfile in openFileDialog1.FileNames) 
      {
        // here myfile represent your selected file name 
      }
      

      【讨论】:

        【解决方案3】:

        在 WinForms 中,查看 OpenFileDialogs FileNames 属性,它将保存所有选定的文件。在 WPF 中,使用 Files 属性。

        【讨论】:

          【解决方案4】:
           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
           }  
           }
          

          【讨论】:

          • 添加一些解释,说明此答案如何帮助 OP 解决当前问题
          • “对列表做一些事情”,例如int X = fff.Count,给出openFileDialog中选中文件的个数。
          【解决方案5】:
          Dim files() as String = IO.Directory.GetFiles(od.SelectedPath)
          Dim Count as string = files.Length
          

          【讨论】:

          • Thsi 将为您提供文件夹中的文件数,而不是用户选择的文件数。
          • 如果您使用的是 FolderBrowserDialog,这将有效。如果您使用 OpenFileDialog ,您可以使用 op.FileNames 获取文件
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-05-12
          • 1970-01-01
          • 2017-12-04
          • 1970-01-01
          • 1970-01-01
          • 2015-05-13
          • 2011-08-12
          相关资源
          最近更新 更多