Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Path.GetFullPath" and network paths

Tags:

c#

.net

path

Why does "Path.GetFullPath" behave strange when resolving paths with relative elements on a network path? Try this small example and compare the results:

using System;
using System.IO;

namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args) {
            Console.WriteLine(Path.GetFullPath(@"C:\Stay\Elim1\Elim2\..\..\SomeFolder"));  // yields C:\Stay\SomeFolder
            Console.WriteLine(Path.GetFullPath(@"\\Stay\Elim1\Elim2\..\..\SomeFolder"));   // yields \\Stay\Elim1\SomeFolder ???
        }
    }
}

It might be a bug or there might be some sense in it, but I don't get it.

(None of the pathes or even parts of it them really exist on my machine, so its merely a string operation)

like image 738
Ole Dittmann Avatar asked Feb 16 '23 19:02

Ole Dittmann


1 Answers

When You use a network path the second part of the path is the Share-name not directory.

Console.WriteLine(Path.GetFullPath(@"C:\SomeDir\Dir1\Dir2\..\..\SomeFolder"));  

C:\SomeDir\SomeFolder

Console.WriteLine(Path.GetFullPath(@"\\Server\ShareName\Dir1\Dir2\..\..\SomeFolder"));

\Server\ShareName\SomeFolder

like image 184
I4V Avatar answered Feb 23 '23 22:02

I4V