Absolute path back to web-relative path *

Question

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?

Answer

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)

(@Tags2k: I have editted the above answer)

< br > via < a class="StackLink" href=" http://stackoverflow.com/questions/3164/" >Absolute path back to web-relative path< /a>
Share on Google Plus

About Cinema Guy

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment