3

I have a complete URL like: A: http://www.domain.com/aaa/bbb/ccc/ddd/eee.ext.

I have a relative URL like: B: ../../fff.ext

I’m looking for the easiest way in .NET C# to combine these two URLs and get: C: http://www.domain.com/aaa/bbb/fff.ext

This is like what browsers does: you’re browsing URL A, then, page’s HTML have an hyperlink as B, the resulting URL is C.

1 Answer 1

5

You'd probably have better luck looking up "PathCanonicalize".

Also, with my findings, one of the overloaded Uri constructors can handle this:

Uri combined = new Uri(
  new Uri("http://www.domain.com/aaa/bbb/ccc/ddd/eee.ext", UriKind.Absolute),
  "../../fff.ext"
);

Proof is in the pudding

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.