If you ever find yourself manually parsing a file name or any part of a path, stop! It’s very tempting to use a couple of lines of code to trim an extension off of a file, but why do it. Also, if you ever have a directory path and a file name, don’t concatenate the two strings together (making sure that a “/” is in between), us Path.Combine instead. I think that a lot of code can be reduced by reusing the BCL. Every now and then you might save 15 minutes by taking 5 minutes to research what is available in the BCL.
Let’s take a look at the System.IO.Path class and see what it can do for us. Just by looking at the following method names, I’m sure you can figure out how to use them to reduce your codebase:
Public Fields
![]() AltDirectorySeparatorCharSupported by the .NET Compact Framework. | Provides a platform-specific alternate character used to separate directory levels in a path string that reflects a hierarchical file system organization. |
![]() DirectorySeparatorCharSupported by the .NET Compact Framework. | Provides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization. |
![]() InvalidPathCharsSupported by the .NET Compact Framework. | Provides a platform-specific array of characters that cannot be specified in path string arguments passed to members of the Path class. |
![]() PathSeparatorSupported by the .NET Compact Framework. | A platform-specific separator character used to separate path strings in environment variables. |
![]() VolumeSeparatorCharSupported by the .NET Compact Framework. | Provides a platform-specific volume separator character. |
Public Methods
![]() ChangeExtensionSupported by the .NET Compact Framework. | Changes the extension of a path string. |
![]() CombineSupported by the .NET Compact Framework. | Combines two path strings. |
![]() GetDirectoryNameSupported by the .NET Compact Framework. | Returns the directory information for the specified path string. |
![]() GetExtensionSupported by the .NET Compact Framework. | Returns the extension of the specified path string. |
![]() GetFileNameSupported by the .NET Compact Framework. | Returns the file name and extension of the specified path string. |
![]() GetFileNameWithoutExtensionSupported by the .NET Compact Framework. | Returns the file name of the specified path string without the extension. |
![]() GetFullPathSupported by the .NET Compact Framework. | Returns the absolute path for the specified path string. |
![]() GetPathRootSupported by the .NET Compact Framework. | Gets the root directory information of the specified path. |
![]() GetTempFileNameSupported by the .NET Compact Framework. | Returns a uniquely named zero-byte temporary file on disk and returns the full path to that file. |
![]() GetTempPathSupported by the .NET Compact Framework. | Returns the path of the current system’s temporary folder. |
![]() HasExtensionSupported by the .NET Compact Framework. | Determines whether a path includes a file name extension. |
![]() IsPathRooted | Gets a value indicating whether the specified path string contains absolute or relative path information. |


