0

I work with this code to open folder and browse files from it, but i need to get this files without open folder,when I run my program automatically load this files, I try to use GetFiles() but didn't work with me when apply the filter for files i want to select
this is my code

OpenFileDialog dlg = new OpenFileDialog();             
dlg.InitialDirectory = @"C:\Users\ahmed\Desktop\samples";
dlg.Filter = "Gestures (*.xml)|*.xml";
dlg.Title = "Load Gestures";
dlg.RestoreDirectory = false;
dlg.Multiselect = true;

if (dlg.ShowDialog(this) == DialogResult.OK)
{
    for (int i = 0; i < dlg.FileNames.Length; i++)
    {
        string name = dlg.FileNames[i];
        _rec.LoadGesture(name);
    }
    ReloadViewForm();
}
sparsh610
  • 1,552
  • 3
  • 27
  • 66
mbugr
  • 322
  • 1
  • 4
  • 23

1 Answers1

2

Try using Directory.GetFiles. It returns the names of files (including their paths) in the specified directory.

var files = Directory.GetFiles("C:\\");

foreach (var file in files)
{
    var fileInfo = new FileInfo(file);
    Console.WriteLine(fileInfo.Name);
}
NeddySpaghetti
  • 13,187
  • 5
  • 32
  • 61