0

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.

3
  • 3
    If you place a debug break on the Request.Url you can see all the items that can give you , like the .Path and can do the job. Is faster than make a question. Commented Nov 7, 2012 at 15:34
  • This question question might be interesting for you stackoverflow.com/questions/4630249/get-url-without-querystring Commented Nov 7, 2012 at 15:39
  • Always the first three parts or remove the "reportview.aspx"? Or to put it in a different way, what if the url is http://localhost/portal/sub/page.aspx? Commented Nov 7, 2012 at 15:41

2 Answers 2

1

Try this;

string s = "http://localhost/portal/reportview.aspx";
string y = string.Format("{0}//{2}/{3}/",s.Split('/'));
Sign up to request clarification or add additional context in comments.

1 Comment

Split finds an empty string between the //, so either shift the indexes or use StringSplitOptions.RemoveEmptyEntries in the Split.
1

You can use substring.

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.