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
![]() ![]() Supported 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. |
![]() ![]() Supported 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. |
![]() ![]() Supported 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. |
![]() ![]() Supported by the .NET Compact Framework. | A platform-specific separator character used to separate path strings in environment variables. |
![]() ![]() Supported by the .NET Compact Framework. | Provides a platform-specific volume separator character. |
Public Methods
![]() ![]() Supported by the .NET Compact Framework. | Changes the extension of a path string. |
![]() ![]() Supported by the .NET Compact Framework. | Combines two path strings. |
![]() ![]() Supported by the .NET Compact Framework. | Returns the directory information for the specified path string. |
![]() ![]() Supported by the .NET Compact Framework. | Returns the extension of the specified path string. |
![]() ![]() Supported by the .NET Compact Framework. | Returns the file name and extension of the specified path string. |
![]() ![]() Supported by the .NET Compact Framework. | Returns the file name of the specified path string without the extension. |
![]() ![]() Supported by the .NET Compact Framework. | Returns the absolute path for the specified path string. |
![]() ![]() Supported by the .NET Compact Framework. | Gets the root directory information of the specified path. |
![]() ![]() Supported by the .NET Compact Framework. | Returns a uniquely named zero-byte temporary file on disk and returns the full path to that file. |
![]() ![]() Supported by the .NET Compact Framework. | Returns the path of the current system’s temporary folder. |
![]() ![]() Supported by the .NET Compact Framework. | Determines whether a path includes a file name extension. |
![]() ![]() | Gets a value indicating whether the specified path string contains absolute or relative path information. |