Farhad-Taran
Farhad-Taran

Reputation: 6540

how to manipulate the URL path in c# asp.net?

I have the following path:

-http://localhost/portal/reportview.aspx

but I need to retrieve the first 3 parts:

-http://localhost/portal/

Ive tried HttpContext.Current.Request.Url.GetLeftPart(); with no luck.

Upvotes: 0

Views: 1302

Answers (2)

Kaf
Kaf

Reputation: 33839

Try this;

string s = "http://localhost/portal/reportview.aspx";
string y = string.Format("{0}//{2}/{3}/",s.Split('/'));

Upvotes: 1

Adil
Adil

Reputation: 148180

You can use substring.

string str = "http://localhost/portal/reportview.aspx";

string left = str.Substring(0, str.LastIndexOf("/"));

Upvotes: 1

Related Questions