33

I have a url like this :

http://www.somesite.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye.

I want to get mypage.aspx?myvalue1=hello&myvalue2=goodbye from it . Can you tell me how can I get it ?

Rocky Singh
  • 15,128
  • 29
  • 99
  • 146

4 Answers4

56

Like this:

new Uri(someString).PathAndQuery
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
43
var uri = new Uri("http://www.somesite.com/mypage.aspx?myvalue1=hello&myvalue2=goodbye");

string pathOnly = uri.LocalPath;        // "/mypage.aspx"
string queryOnly = uri.Query;           // "?myvalue1=hello&myvalue2=goodbye"
string pathAndQuery = uri.PathAndQuery; // "/mypage.aspx?myvalue1=hello&myvalue2=goodbye"
Chris Marisic
  • 32,487
  • 24
  • 164
  • 258
HABJAN
  • 9,212
  • 3
  • 35
  • 59
0

Place your string URL into a URI object and then use the AbsolutePath & Query properties to get the URL parts you need.

Or use the PathAndQuery property to get both, which is what you need.

More information can be found here:

http://msdn.microsoft.com/en-us/library/system.uri_members%28v=VS.71%29.aspx

MrEyes
  • 13,059
  • 10
  • 48
  • 68
0

new Uri(System.AppDomain.CurrentDomain.BaseDirectory).Segments

RJ Thompson
  • 126
  • 7