Path.GetDirectoryName returns null on UNC path

Path.GetDirectoryName(@"C:\\");

      

returns null and

Path.GetDirectoryName(@"C:\\Foo");

      

returns C: \

Although this is exactly what the documentation mentions I am wondering why

Path.GetDirectoryName(@"\\server.domain.tld\Foo");

      

returns null, not as I expected \ server.domain.tld \

Does anyone know why?

+3


source to share


1 answer


Generally the structure of the path is UNC \\{server}\{share}\{path.....}

, so "Foo"

in your example UNC is equivalent to "C:\"

your first example. This is why you get null

UNC path for your example.



The path "\\server\foo\bar"

will be"bar"

+2


source







All Articles