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

AWS EC2 Can't Reach EC2 Metadata Service After Subnet Change

A2 Hosting with .NET Core 2.1

Xcode CodeSign Incorrectly States Password is Incorrect