Path Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Inheritance Hierarchy

System.Object
  System.IO.Path

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

Syntax

'Declaration
<ComVisibleAttribute(True)> _
Public NotInheritable Class Path
[ComVisibleAttribute(true)]
public static class Path

The Path type exposes the following members.

Methods

  Name Description
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 ChangeExtension When it is called by trusted applications, changes the extension of a path string.
Public methodStatic member Combine(array<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 360 Combine(String, String) When it is called by trusted applications, combines two path strings.
Public methodStatic member Combine(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 360 GetDirectoryName When 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 360 GetExtension When it is called by trusted applications, returns the extension of the specified path string.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetFileName When 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 360 GetFileNameWithoutExtension When 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 360 GetFullPath When 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 360 GetInvalidPathChars When 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 360 GetPathRoot Gets the root directory information of the specified path.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetTempFileName Creates 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 360 GetTempPath Returns the path of the current system's temporary folder.
Public methodStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 HasExtension When 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 360 IsPathRooted Gets a value indicating whether the specified path string contains a root.

Top

Fields

  Name Description
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 AltDirectorySeparatorChar Provides 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 360 DirectorySeparatorChar Provides 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 360 PathSeparator A platform-specific separator character used to separate path strings in environment variables.
Public fieldStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 VolumeSeparatorChar Provides a platform-specific volume separator character.

Top

Remarks

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.

Examples

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.
Dim subdirectory1 As String = Path.Combine("MyApp1", "SubDir1")
Dim subdirectory2 As String = Path.Combine("MyApp1", "SubDir2")
Dim subdirectory3 As String = Path.Combine("MyApp1", "SubDir3")
store.CreateDirectory(subdirectory1)
store.CreateDirectory(subdirectory2)
store.CreateDirectory(subdirectory3)
// 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);

Version Information

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

Platforms

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

Thread Safety

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

See Also

Reference

Other Resources