2

How to know how many files selected in opendialog in c# ?

Andrius Naruševičius
  • 8,348
  • 7
  • 49
  • 78
SWE
  • 131
  • 2
  • 7
  • 20

5 Answers5

3

.FileNames will probably hold the count of selected items :)

Andrius Naruševičius
  • 8,348
  • 7
  • 49
  • 78
3

FileDialog.FileNames Property

Gets the file names of all selected files in the dialog box.

For example

foreach (String myfile in openFileDialog1.FileNames) 
{
  // here myfile represent your selected file name 
}
Amit
  • 21,570
  • 27
  • 74
  • 94
1

In WinForms, check out the OpenFileDialogs FileNames property, which will hold all the selected files. In WPF, use the Files property.

zmbq
  • 38,013
  • 14
  • 101
  • 171
0
 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
 }  
 }
-2
Dim files() as String = IO.Directory.GetFiles(od.SelectedPath)
Dim Count as string = files.Length
Ali Tarhini
  • 5,278
  • 6
  • 41
  • 66
  • 3
    Thsi will get you the number of files in the folders, not the number of files selected by the user. – zmbq May 19 '12 at 21:23
  • this works if you are using FolderBrowserDialog. if you use OpenFileDialog u can get the files with op.FileNames – Ali Tarhini May 19 '12 at 21:25