2021年3月17日星期三

How to combine file absolute and relative uri or path in C#

What I want to implement is a combining function that takes one absolute path/uri and one relative path/uri and returns the two combined. For instance, consider these two paths:

var root = "c:\src";  var images = "/images/logo.png" ;  var combined = Combine (root, images); // Either 'c:/src/images/logo.png' or 'c:\src\images\logo.png' is acceptable  

I want to avoid manually manipulating/intercepting forward and backward slashes and I want to stick to .Net built-in functionalities. I tried Uri and Path.Combine but no luck. The biggest problem is that the images starts with a forwarding slash, still I guess there must be a way to tell .Net to treat it as relative to the absolute path.

https://stackoverflow.com/questions/66683755/how-to-combine-file-absolute-and-relative-uri-or-path-in-c-sharp March 18, 2021 at 10:01AM

没有评论:

发表评论