How to save the file names in an array? When opening the Open File Dialog the path is obtained and in an array all the names of images or files are saved.
Thank you.
How to save the file names in an array? When opening the Open File Dialog the path is obtained and in an array all the names of images or files are saved.
Thank you.
Use the method GetFiles()
of class Directory
.
This will return an array with all the files that match the search criteria, for example:
ruta = @"c:\users\juan\documents";
string[] archivos = Directory.GetFiles(ruta, "*.jpg");
It will return all files with .jpg
extension that are in my document folder.
You can not use OpenFileDialog
to get a route, for that the FolderBrowserDialog
string[] arrayNombres;
using(var folderBrowserDialog1 = new FolderBrowserDialog())
{
DialogResult result = folderBrowserDialog1.ShowDialog();
if( result == DialogResult.OK )
{
string folderName = folderBrowserDialog1.SelectedPath;
arrayNombres = Directory.GetFiles(folderName, "*.*");
}
}
Using Directory.GetFiles()
you get the files in the folder
How to: Choose folders with the FolderBrowserDialog component of Windows Forms