Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path.GetDirectoryName returns null on UNC path

Tags:

c#

.net

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

returns null and

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

returns C:\

While this is exactly the behaviour mentioned in the documentation I'm wondering why

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

returns null and not as I'd have expected \server.domain.tld\

Does anyone have clue why?

like image 931
Bill Tür stands with Ukraine Avatar asked Nov 01 '22 16:11

Bill Tür stands with Ukraine


1 Answers

Typically, the UNC path structure is \\{server}\{share}\{path.....}, so "Foo" in your UNC example is equivalent to the "C:\" of your first example. This is why you get null for the path of your UNC example.

The path of "\\server\foo\bar" would be "bar"

like image 100
Jon G Avatar answered Nov 15 '22 06:11

Jon G