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

2.5k views Asked by At

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

5

There are 5 answers

0
Andrius Naruševičius On BEST ANSWER

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

2
Ali Tarhini On
Dim files() as String = IO.Directory.GetFiles(od.SelectedPath)
Dim Count as string = files.Length
0
Amit On

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 
}
0
zmbq On

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

2
Horia Georgescu On
 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
 }  
 }