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.

Version Notes

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.