Path.Combine and Path.GetFullPath

I bumped into a case in which I need to resolve a relative path to a file, but the problem is it doesn't resolve as expected when Path.GetFullPath is used.

For example:
path1 = "C:\file\"
path2 = "..\test.txt"
Path.Combine produces "C:\file\..\test.txt"
Path.GetFullPath((New Uri(Path.Combine(path1,path2))).LocalPath) produces "C:\test.txt" which is correct.

The problem starts when I realized another slash was accidentally appended to the end of path1.

path1 = "C:\file\"
path2 = "..\test.txt"
Path.Combine produces "C:\file\\..\test.txt"
Path.GetFullPath((New Uri(Path.Combine(path1,path2))).LocalPath) produces "C:\file\test.txt" which is correct but unexpected.


Comments

Popular posts from this blog

Sentinel One Strikes Again. No internet connection. Uninstall Sentinel One Agent.

A2 Hosting Let's Encrypt Can't Install Certificate on ASP.NET Core Application

NuGet Package Reference NU6105 Publish Error