GetInvalidPathChars not listing all invalid path chars

I am writing a .NET program using c# and ran across this.

GetInvalidPathChars doesnt seem to return a question mark but windows will not allow me to create a folder with a question mark in it.  This makes me think the list returned by GetInvalidPathChars is incomplete (thus useless for preventing errors).  Is there something else i should be using in my function to remove invalid characters from a string (that will be used to create a file name)?

Thanks,
LVL 15
dave4dlAsked:
Who is Participating?
 
anarki_jimbelConnect With a Mentor Commented:
Arabia_vn is completely right: "The array returned from this method is not guaranteed to contain the complete set of characters that are invalid in file and directory names. "  (http://msdn.microsoft.com/en-us/library/system.io.path.getinvalidpathchars.aspx)

However MS does not guarantee the right output for another method:
http://msdn.microsoft.com/en-us/library/system.io.path.getinvalidfilenamechars(v=VS.100).aspx

So the above suggestion is not quite right. On another hand, the second method returns "?".

I'd probably write my own procedure to limit characters to Latin alphabet, digits, space, underscore and might be couple another characters...

0
 
Arabia_vnConnect With a Mentor Commented:
Yes that method is totally useless since it does return invalid characters but not ALL. I think you better use System.IO.Path.GetInvalidFileNameChars instead. Read this http://msdn.microsoft.com/en-us/library/system.io.path.getinvalidfilenamechars.aspx
0
 
dave4dlAuthor Commented:
Thank you both for your help.  I ended up writing my own function to ensure my file name was ok.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.