Search code examples
c#asp.net.netpathmappath

Absolute path back to web-relative path


If I have managed to locate and verify the existence of a file using Server.MapPath and I now want to send the user directly to that file, what is the fastest way to convert that absolute path back into a relative web path?


Solution

  • Perhaps this might work:

    String RelativePath = AbsolutePath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty);
    

    I'm using c# but could be adapted to vb.