Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Path.InvalidPathChars question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
schaf - 23 Nov 2006 07:17 GMT
Hi !
I have determined, that Path.InvalidPathChars does not return an array
with all  invalid path characters. For instance the question mark (?)
does not appear in the array, but it is not possible to create a folder
with a question mark (?).

How can I get the whole range of invalid path characters ? Or is it the
best way, to create a folder and using try/catch ?

Regards
Ciaran O''Donnell - 23 Nov 2006 09:38 GMT
You should try catch it as it isnt garunteed to work even with a good name as
permissions or name clashes could still get in the way. Plus it may change in
future OS's. Spaces didnt used to be allowed in windows.

Ciaran O'Donnell

> Hi !
> I have determined, that Path.InvalidPathChars does not return an array
[quoted text clipped - 6 lines]
>
> Regards
marss - 23 Nov 2006 09:58 GMT
> Hi !
> I have determined, that Path.InvalidPathChars does not return an array
> with all  invalid path characters. For instance the question mark (?)
> does not appear in the array, but it is not possible to create a folder
> with a question mark (?).

Hi,
MSDN: This array (InvalidPathChars) is not guaranteed to contain the
complete set of characters that are invalid in file and directory
names. The full set of invalid characters can vary by file system...

> How can I get the whole range of invalid path characters ? Or is it the
> best way, to create a folder and using try/catch ?
>
> Regards

Alternative way is to leave in the path name only exactly valid
characters instead of looking for possible invalid ones.
Ex.:
string path = @"c:\\test\df ?sdg\1.txt";
System.Text.RegularExpressions.Regex re = new
System.Text.RegularExpressions.Regex(@"[^\w\\:.]+");
path = re.Replace(path, "");
Maybe it helps somehow.
schaf - 23 Nov 2006 10:12 GMT
Hi marss

> Alternative way is to leave in the path name only exactly valid
> characters instead of looking for possible invalid ones.
[quoted text clipped - 4 lines]
> path = re.Replace(path, "");
> Maybe it helps somehow.

I have a similar alternative way, I do not want to update my regex or
char-array, each time the user changes the OS. And I'm not sure, if the
chinese version of windows has the same invalid character like a german
or english windows.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.