I am testing a class with a console application and in the class the user is asked to select a file. I create a OpenFileDialog class instance, set the filters, activate multiselect and call ShowDialog(). I select a file/s and it returns true but there's an empty string on the field FileName an a 0 items string[] in FileNames. What am I missing?
Here is the code:
private static string[] OpenFileSelector(string extension1)
{
OpenFileDialog op = new OpenFileDialog();
op.InitialDirectory = @"C:\";
op.Title = "Seleccione los archivos";
op.Filter = "|*." + extension1;
op.Multiselect = true;
bool? res = op.ShowDialog();
if (res != null && res.Value) return op.FileNames;
return null;
}
Extension is never empty and I've tried with several file extensions. For the record, I used the Forms class before the Win32 and it worked fine.
op.Filter =
Text Files (.txt)|.txt|All Files (.)|*.*` if you need to add different types then you should probable build the filter using thestring.Format
function also why did you not look here first MSDN OpenFileDialog.Filter Property – MethodMan