You can get most of this lesson from the Uri class:
new Uri("http://myserver.com/home.aspx").AbsolutePath
Then you just need to add ~
Although, this may break if you place it in a subdirectory - I do not think there is a way to do this specifically in the context of the application in which you are working.
EDIT: This can do it:
VirtualPathUtility.ToAppRelative(new Uri("http://myserver.com/home.aspx").AbsolutePath);
Daniel Schaffer
source share