0

Whats the equivalent to System.IO.Path ?

I got this url: http://www.website.com/category1/category2/file.aspx?data=123

How can i break this down, like

var url = ASPNETPATH("http://www.website.com/category1/category2/file.aspx?data=123");

url.domain <-- this would then return http://www.website.com

url.folder <-- would return category1/category2

url.file <-- would return file.aspx

url.queryString <-- would return the querystring in some format

3 Answers 3

7

Use the UriBuilder class:
http://msdn.microsoft.com/en-us/library/system.uribuilder.aspx

UriBuilder uriBuilder = new UriBuilder("http://www.somesite.com/requests/somepage.aspx?i=123");
string host = uriBuilder.Host;     // www.somesite.com
string query = uriBuilder.Query;   // ?i=123
string path = uriBuilder.Path;     // /requests/somepage.aspx
Sign up to request clarification or add additional context in comments.

Comments

4

Check out the URI Class you can get all of that information using that class.

Comments

0

Regular expressions are perfect to use for this. Here's a link that has some nice info on using them. http://www.regular-expressions.info/

Edit : I forgot C# has a URI class which you can use for this as well.

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.