VirtualPathUtility class

Found this nice utility class while browsing through the reflector. It provides utility methods for common operations involving virtual paths.

Here's an example taken from the msdn page.


    StringBuilder sb = new StringBuilder();
    String pathstring = Context.Request.FilePath.ToString();
    sb.Append("Current file path = " + pathstring + "<br>");
    sb.Append("File name = " + VirtualPathUtility.GetFileName(pathstring).ToString() + "<br>");
    sb.Append("File extension = " + VirtualPathUtility.GetExtension(pathstring).ToString() + "<br>");
    sb.Append("Directory = " + VirtualPathUtility.GetDirectory(pathstring).ToString() + "<br>");
    Response.Write(sb.ToString());
   
    StringBuilder sb2 = new StringBuilder();
    String pathstring1 = Context.Request.CurrentExecutionFilePath.ToString();
    sb2.Append("Current Executing File Path = " + pathstring1.ToString() + "<br>");
    sb2.Append("Is Absolute = " + VirtualPathUtility.IsAbsolute(pathstring1).ToString() + "<br>");
    sb2.Append("Is AppRelative = " + VirtualPathUtility.IsAppRelative(pathstring1).ToString() + "<br>");
    sb2.Append("Make AppRelative = " + VirtualPathUtility.ToAppRelative(pathstring1).ToString() + "<br>");
    Response.Write(sb2.ToString());


Read more about it here.
Published Saturday, December 17, 2005 12:38 PM by admin
Filed Under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

What do you think?

(required) 
required 
optional
required