0

Is there an out of the box way to append a path to an existing Uri in C#?

What I have currently is something like this. To be clear, I'd like to avoid using uriBuilder.Path += because that way I'd have to specify path slashes myself.

string current = "https://www.test.com/api/test/something?something=123";
string stuff = "getsomething";

My Preferred output would be https://www.test.com/api/test/something/getsomething?something=123. Of course, I could manually try to do it, but am I able to append the "getsomething" onto the path without losing the current one?

TheDoomDestroyer
  • 2,434
  • 4
  • 24
  • 45
  • 2
    https://learn.microsoft.com/en-us/dotnet/api/system.uribuilder.path?view=netcore-3.1 - read and set this property. – mjwills Jul 14 '20 at 08:34
  • 1
    I was going to answer this, but the question got closed before I could. I created a fiddle here: [https://dotnetfiddle.net/yQQiH6](https://dotnetfiddle.net/yQQiH6) – Neophear Jul 14 '20 at 08:53
  • 1
    Cheers everyone for no help. Marking the question as duplicate while the other doesn't do anything as similar as what was asked here is a wonderful thing. Appreciate it. – TheDoomDestroyer Jul 14 '20 at 09:27
  • @Sinatr I have and yes, it does work, but it doesn't really do much for the "out of the box" part since I manually have to add a slash before calling `uriBuilder.Path +=`. – TheDoomDestroyer Jul 14 '20 at 10:14
  • 1
    So you want to [manipulate url](https://stackoverflow.com/q/372865/1997232)? – Sinatr Jul 14 '20 at 10:28

0 Answers0