Export (0) Print
Expand All

Path Class

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)

[ComVisibleAttribute(true)]
public static class Path

The Path type exposes the following members.

  NameDescription
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360ChangeExtensionWhen it is called by trusted applications, changes the extension of a path string.
Public methodStatic memberCombine(String[])When it is called by trusted applications, combines an array of strings into a path.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360Combine(String, String)When it is called by trusted applications, combines two path strings.
Public methodStatic memberCombine(String, String, String)When it is called by trusted applications, combines four strings into a path.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetDirectoryNameWhen it is called by trusted applications, returns the directory information for the specified path string.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetExtensionWhen it is called by trusted applications, returns the extension of the specified path string.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetFileNameWhen it is called by trusted applications, returns the file name and extension of the specified path string.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetFileNameWithoutExtensionWhen it is called by trusted applications, returns the file name of the specified path string without the extension.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetFullPathWhen it is called by trusted applications, returns the absolute path for the specified path string.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetInvalidPathCharsWhen it is called by trusted applications, gets an array containing the characters that are not allowed in path names.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetPathRootGets the root directory information of the specified path.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetTempFileNameCreates a uniquely named, zero-byte temporary file on disk and returns the full path of that file.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360GetTempPathReturns the path of the current system's temporary folder.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360HasExtensionWhen it is called by trusted applications, determines whether a path includes a file name extension.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360IsPathRootedGets a value indicating whether the specified path string contains a root.
Top

  NameDescription
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360AltDirectorySeparatorCharProvides a platform-specific alternate character used to separate directory levels in a path string that reflects a hierarchical file system organization.
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360DirectorySeparatorCharProvides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization.
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360PathSeparatorA platform-specific separator character used to separate path strings in environment variables.
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360VolumeSeparatorCharProvides a platform-specific volume separator character.
Top

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.

NoteNote:

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);


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

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

Community Additions

ADD
Show:
© 2014 Microsoft