Blog Stats
  • Posts - 4
  • Articles - 0
  • Comments - 17
  • Trackbacks - 5

 

Thursday, August 03, 2006

Reverse Server.MapPath()

Here's a simple ASP.NET function that will get the opposite result of the Server.MapPath() function.  This comes in handy when you're retrieving files recently saved by your web application.  Pass it a fully qualified path and it returns a URL

Public Function MapURL(ByVal Path As String) As String
     Dim AppPath As String = _
    
HttpContext.Current.Server.MapPath("~")
     Dim url As String = String.Format("~{0}" _
     
, Path.Replace(AppPath, "").Replace("\", "/"))
     Return url
End Function

Of course, you will have to make sure that the path is valid and the file is under the virtual root.

Enjoy!

 

 

Copyright © Albert Raiani