Click here to Skip to main content
15,912,977 members
Home / Discussions / C#
   

C#

 
QuestionChecking if string path is valid [modified] Pin
Saksida Bojan6-Mar-10 0:24
Saksida Bojan6-Mar-10 0:24 
AnswerRe: Checking if string path is valid Pin
#realJSOP6-Mar-10 1:01
professional#realJSOP6-Mar-10 1:01 
GeneralRe: Checking if string path is valid Pin
Saksida Bojan6-Mar-10 1:03
Saksida Bojan6-Mar-10 1:03 
GeneralRe: Checking if string path is valid Pin
#realJSOP6-Mar-10 1:55
professional#realJSOP6-Mar-10 1:55 
GeneralRe: Checking if string path is valid Pin
Saksida Bojan6-Mar-10 2:06
Saksida Bojan6-Mar-10 2:06 
GeneralRe: Checking if string path is valid Pin
#realJSOP6-Mar-10 3:45
professional#realJSOP6-Mar-10 3:45 
GeneralRe: Checking if string path is valid Pin
Saksida Bojan6-Mar-10 3:54
Saksida Bojan6-Mar-10 3:54 
AnswerRe: Checking if string path is valid Pin
AspDotNetDev6-Mar-10 2:56
protectorAspDotNetDev6-Mar-10 2:56 
Ah, so you just want to see if a hypothetical path (which may or may not already exist on the file system) is valid as far as the characters it uses and length and such? In that case, you have two options. Option 1 would be to use this code and catch exceptions for invalid characters and such (various types of exceptions will be thrown based on how the path is invalid):
C#
// These will throw exceptions.
DirectoryInfo di = new DirectoryInfo("***");
FileInfo fi = new FileInfo("***");

The other option is to check this manually. Some things to consider when creating this code:
Path.AltDirectorySeparatorChar
Path.DirectorySeparatorChar
Path.GetInvalidFileNameChars()
Path.GetInvalidPathChars()
Check if root drives exist (may not apply to network paths)
Avoid known bad folder names (e.g., COM or something like that is invalid because it is reserved).
Path.VolumeSeparatorChar
Maximum path length (260 characters?) and max filename length.
If the path does exist, then it must be valid (but determining if it is invalid will take more work).
GeneralRe: Checking if string path is valid Pin
Saksida Bojan6-Mar-10 3:17
Saksida Bojan6-Mar-10 3:17 
AnswerRe: Checking if string path is valid Pin
PIEBALDconsult6-Mar-10 3:17
mvePIEBALDconsult6-Mar-10 3:17 
GeneralRe: Checking if string path is valid Pin
Saksida Bojan6-Mar-10 3:31
Saksida Bojan6-Mar-10 3:31 
GeneralRe: Checking if string path is valid Pin
PIEBALDconsult6-Mar-10 16:15
mvePIEBALDconsult6-Mar-10 16:15 
AnswerRe: Checking if string path is valid Pin
Eddy Vluggen6-Mar-10 3:21
professionalEddy Vluggen6-Mar-10 3:21 
GeneralRe: Checking if string path is valid Pin
Saksida Bojan6-Mar-10 3:36
Saksida Bojan6-Mar-10 3:36 
AnswerRe: Checking if string path is valid Pin
Luc Pattyn6-Mar-10 4:30
sitebuilderLuc Pattyn6-Mar-10 4:30 
GeneralRe: Checking if string path is valid Pin
Saksida Bojan6-Mar-10 10:58
Saksida Bojan6-Mar-10 10:58 
AnswerRe: Checking if string path is valid Pin
RichardM16-Mar-10 7:54
RichardM16-Mar-10 7:54 
AnswerRe: Checking if string path is valid Pin
Giorgi Dalakishvili6-Mar-10 10:09
mentorGiorgi Dalakishvili6-Mar-10 10:09 
QuestionDefault Code view. Pin
Saksida Bojan5-Mar-10 23:11
Saksida Bojan5-Mar-10 23:11 
AnswerRe: Default Code view. Pin
1.21 Gigawatts5-Mar-10 23:29
1.21 Gigawatts5-Mar-10 23:29 
GeneralRe: Default Code view. Pin
Saksida Bojan5-Mar-10 23:48
Saksida Bojan5-Mar-10 23:48 
GeneralRe: Default Code view. Pin
1.21 Gigawatts5-Mar-10 23:52
1.21 Gigawatts5-Mar-10 23:52 
GeneralRe: Default Code view. Pin
Luc Pattyn6-Mar-10 4:32
sitebuilderLuc Pattyn6-Mar-10 4:32 
GeneralRe: Default Code view. Pin
1.21 Gigawatts6-Mar-10 6:15
1.21 Gigawatts6-Mar-10 6:15 
QuestionZip Folders and Files Pin
Anil Kumar.Arvapalli5-Mar-10 21:38
Anil Kumar.Arvapalli5-Mar-10 21:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.