Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uri(Uri, String) constructor does not works properly?

Tags:

c#

.net

Here is a part of my code:

Uri branches = new Uri(@"https://127.0.0.1:8443/svn/CXB1/Validation/branches");
Uri testBranch = new Uri(branches, "test");

I expect testBranches will be https://127.0.0.1:8443/svn/CXB1/Validation/branches/test, but it is https://127.0.0.1:8443/svn/CXB1/Validation/test. I can not understand why Uri(Uri, string) constructor eats the last part of the path.

like image 551
Max Avatar asked Aug 22 '13 07:08

Max


2 Answers

Add a slash after branches

  Uri branches = new Uri(@"https://127.0.0.1:8443/svn/CXB1/Validation/branches/");
  Uri testBranch = new Uri(branches, "test");
like image 194
Kimtho6 Avatar answered Sep 21 '22 02:09

Kimtho6


The Behaviour you see is correct, because replacing the last part is a good idea if you want to change the filename.

I would add the backslash at the end of the first part. Then it is clear that this is a directory, otherwise it may be interpretated as a file.

Uri branches = new Uri(@"https://127.0.0.1:8443/svn/CXB1/Validation/branches/");
Uri testBranch = new Uri(branches, "test");
Console.WriteLine(testBranch);

Will get this output:

 https://127.0.0.1:8443/svn/CXB1/Validation/branches/test
like image 3
S.Spieker Avatar answered Sep 21 '22 02:09

S.Spieker