May 11, 2014
Performs operations on String instances that contain file or directory path information. These operations are performed in a cross-platform manner.
Assembly: mscorlib (in mscorlib.dll)
Thetype exposes the following members.
|ChangeExtension||Changes the extension of a path string.|
|Combine(String)||Combines an array of strings into a path.|
|Combine(String, String)||Combines two path strings.|
|GetDirectoryName||Returns the directory information for the specified path string.|
|GetExtension||Returns the extension of the specified path string.|
|GetFileName||Returns the file name and extension of the specified path string.|
|GetFileNameWithoutExtension||Returns the file name of the specified path string without the extension.|
|GetFullPath||Returns the absolute path for the specified path string.|
|GetInvalidFileNameChars||Gets an array containing the characters that are not allowed in file names.|
|GetInvalidPathChars||Gets an array containing the characters that are not allowed in path names.|
|GetPathRoot||Gets the root directory information of the specified path.|
|GetRandomFileName||Returns a random folder name or file name.|
|GetTempFileName||Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file.|
|GetTempPath||Returns the path of the current system's temporary folder.|
|HasExtension||Determines whether a path includes a file name extension.|
|IsPathRooted||Gets a value indicating whether the specified path string contains a root.|
|AltDirectorySeparatorChar||Provides a platform-specific alternate character used to separate directory levels in a path string that reflects a hierarchical file system organization.|
|DirectorySeparatorChar||Provides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization.|
|PathSeparator||A platform-specific separator character used to separate path strings in environment variables.|
|VolumeSeparatorChar||Provides a platform-specific volume separator character.|
A path can contain absolute or relative location information in isolated storage. Absolute paths fully specify a location: the file or directory can be uniquely identified regardless of the current location. Relative paths specify a partial location: the current location is used as the starting point when locating a file specified with a relative path.
Most members of the class do not interact with the file system and do not verify the existence of the file specified by a path string. class members that modify a path string, such as ChangeExtension, have no effect on names of files in the file system. members do, however, validate the contents of a specified path string, and throw an ArgumentException if the string contains characters that are not valid in path strings. For example, on Windows-based desktop platforms, invalid path characters might include quote ("), less than (<), greater than (>), pipe (|), backspace (\b), null (\0), and Unicode characters 16 through 18 and 20 through 25.
The members of the class enable you to quickly and easily perform common operations such as determining whether a file name extension is part of a path, and combining two strings into one path name.
All members of the class are static and can therefore be called without having an instance of a path.
In members that accept a path as an input string, that path must be well-formed or an exception is raised. For example, if a path is fully qualified but begins with a space, the path is not trimmed in methods of the class. Therefore, the path is malformed and an exception is raised. Similarly, a path or a combination of paths cannot be fully qualified twice. Ensure that your paths are well-formed when using methods that accept a path string.
In members that accept a path, the path can refer to a file or just a directory.
Because all these operations are performed on strings, it is impossible to verify that the results are valid in all scenarios. For example, the GetExtension method parses a string that you pass to it and returns the extension from that string. However, this does not confirm that a file with that extension exists on the disk.
The following example combines directory and subdirectory names into paths for creating the directories in isolated storage. This example is part of a larger example provided for the IsolatedStorageFile class.
// Create three subdirectories under MyApp1. string subdirectory1 = Path.Combine("MyApp1", "SubDir1"); string subdirectory2 = Path.Combine("MyApp1", "SubDir2"); string subdirectory3 = Path.Combine("MyApp1", "SubDir3"); store.CreateDirectory(subdirectory1); store.CreateDirectory(subdirectory2); store.CreateDirectory(subdirectory3);