0

I'm using Custom WPF Dialog box to select one or more files. Problem is that When you select more than a file, it'll throw Argumentexception("Illegal characters in path.") because of

void  OnPathChanged(IFileDlgExt sender, string pathName)
method on FileDialogExt class. Reason for issue is that pathName for multiple file is like:
D:\Development\ "WpfCustomFileDialog.dll"  "WpfCustomFileDialog.pdb"
Which is not a valid parameter for
System.IO.Path.GetFileName
and it'll throw Argumentexception("Illegal characters in path.").

How can I fix this it?

Regards

Ben
  • 1,196
  • 2
  • 11
  • 25

1 Answers1

2

It doesn't look like there's anything to fix, really, though it is a lousy return value. You just need to separate or parse your returned pathName and call GetFileName() with each actual name.

Assuming your D:\ line is a string, you should be able to .Split('"'). Iterate through the resulting array to .Trim() the errant whitespace and get rid of the now-empty entries (the spaces between quoted names).

If you then combine the first array element (the folder) with each other element (the file), those should be your valid file names.

If you're including the project as source, you might want to do this work inside the window, and return a List<String> or something, rather than that ugly string.

John C
  • 1,931
  • 1
  • 22
  • 34