Path Class

Path Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Performs operations on String instances that contain file or directory path information. These operations are performed in a cross-platform manner.


Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)

public static class Path

The Path type exposes the following members.

Public methodStatic memberChangeExtensionChanges the extension of a path string.
Public methodStatic memberCombine(String[])Combines an array of strings into a path.
Public methodStatic memberCombine(String, String)Combines two path strings.
Public methodStatic memberGetDirectoryNameReturns the directory information for the specified path string.
Public methodStatic memberGetExtensionReturns the extension of the specified path string.
Public methodStatic memberGetFileNameReturns the file name and extension of the specified path string.
Public methodStatic memberGetFileNameWithoutExtensionReturns the file name of the specified path string without the extension.
Public methodStatic memberGetFullPathReturns the absolute path for the specified path string.
Public methodStatic memberGetInvalidFileNameCharsGets an array containing the characters that are not allowed in file names.
Public methodStatic memberGetInvalidPathCharsGets an array containing the characters that are not allowed in path names.
Public methodStatic memberGetPathRootGets the root directory information of the specified path.
Public methodStatic memberGetRandomFileNameReturns a random folder name or file name.
Public methodStatic memberGetTempFileNameCreates a uniquely named, zero-byte temporary file on disk and returns the full path of that file.
Public methodStatic memberGetTempPathReturns the path of the current system's temporary folder.
Public methodStatic memberHasExtensionDetermines whether a path includes a file name extension.
Public methodStatic memberIsPathRootedGets a value indicating whether the specified path string contains a root.

Public fieldStatic memberAltDirectorySeparatorCharProvides a platform-specific alternate character used to separate directory levels in a path string that reflects a hierarchical file system organization.
Public fieldStatic memberDirectorySeparatorCharProvides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization.
Public fieldStatic memberPathSeparatorA platform-specific separator character used to separate path strings in environment variables.
Public fieldStatic memberVolumeSeparatorCharProvides 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 Path class do not interact with the file system and do not verify the existence of the file specified by a path string. Path class members that modify a path string, such as ChangeExtension, have no effect on names of files in the file system. Path 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 Path 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 Path 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");

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

© 2017 Microsoft