Sdílet prostřednictvím


Path.GetDirectoryName Method

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

When it is called by trusted applications, returns the directory information for the specified path string.

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

Syntax

'Declaration
Public Shared Function GetDirectoryName ( _
    path As String _
) As String
public static string GetDirectoryName(
    string path
)

Parameters

Return Value

Type: System.String
A string that contains directory information for path, or nulla null reference (Nothing in Visual Basic) if path denotes a root directory or is nulla null reference (Nothing in Visual Basic). Returns String.Empty if path does not contain directory information.

Exceptions

Exception Condition
ArgumentException

The path parameter contains invalid characters, is empty, or contains only white spaces.

PathTooLongException

The path parameter is longer than the system-defined maximum length.

Remarks

In most cases, the string returned by this method consists of all characters in the path up to but not including the last DirectorySeparatorChar or AltDirectorySeparatorChar. If the path consists of a root directory, such as "c:\", null is returned. Note that this method does not support paths using "file:". Because the returned path does not include the DirectorySeparatorChar or AltDirectorySeparatorChar, passing the returned path back into the GetDirectoryName method will result in the truncation of one folder level per subsequent call on the result string.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

 If you pass an invalid path in GetDirectoryName, the method does not throw an exception. For example, System.IO.Path.GetDirectoryName(@"D:\temp\ .") returns D:\temp instead of throwing an exception. GetDirectoryName also does not throw an exception when the source path is longer than the system-defined maximum path length.

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.

See Also

Reference

Other Resources