How to know how many files selected in opendialog in c# ?
How to know how many selected files in opendialog in c#?
2.6k Views Asked by SWE At
5
There are 5 best solutions below
2

Dim files() as String = IO.Directory.GetFiles(od.SelectedPath)
Dim Count as string = files.Length
0

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

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

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
}
}
.FileNames will probably hold the count of selected items :)