Reputation: 5592
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
Upvotes: 0
Views: 272
Reputation: 34810
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
Upvotes: 7
Reputation: 23268
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.
Upvotes: 0