31

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
  • 14,618
  • 29
  • 93
  • 145

4 Answers4

53

Like this:

new Uri(someString).PathAndQuery
SLaks
  • 837,282
  • 173
  • 1,862
  • 1,933
39
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
  • 31,683
  • 22
  • 160
  • 255
HABJAN
  • 8,943
  • 3
  • 34
  • 56
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
  • 12,287
  • 9
  • 46
  • 66
0

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

RJ Thompson
  • 126
  • 7