tags:

views:

49

answers:

2

Hi,

I have urls with references to folders that are not direct ancestors of the page pointed to - like these below:

    http://www.mysite.com/home/../help/helppage.aspx

    http://www.mysite.com/contact/../help/helppage.aspx

    http://www.mysite.com/accounts/performing-accounts/../../help/helppage.aspx

I'd like to be able to unambiguously resolve these to

http://www.mysite.com/help/helppage.aspx.

How do I do this in C#?

+1  A: 

Use the System.Uri class

Uri uri = new Uri(url);
string absolutePath = uri.AbsolutePath;
Moron
AbsolutePath will drop the domain / prefix, I think he wants AbsoluteUri. But still +1 for beating me to the post :)
Cory Charlton
+2  A: 
Uri uri = new Uri("http://www.mysite.com/home/../help/helppage.aspx");
uri.AbsoluteUri; // <- Contains http://www.mysite.com/help/helppage.aspx
Cory Charlton
+1 for the right answer :-)
Moron