How to know how many files selected in opendialog in c# ?
Asked
Active
Viewed 2,468 times
5 Answers
3
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
}
}
-
1Add some explanation with answer for how this answer help OP in fixing current issue – ρяσѕρєя K Apr 17 '17 at 12:02
-
"Do something with the list", e.g. int X = fff.Count, which gives the number of the selected files in openFileDialog. – Horia Georgescu Apr 17 '17 at 21:40
-2
Dim files() as String = IO.Directory.GetFiles(od.SelectedPath)
Dim Count as string = files.Length

Ali Tarhini
- 5,278
- 6
- 41
- 66
-
3Thsi 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