Sunday, April 15, 2007

ASP.NET - convert a physical path to virtual path

I've seen this question asked several times on forums with many different answers provided. Here's another way to achieve that goal.

If you are 100% sure that your file is below your physical application root, you can just do the following:

virtualFilePath = physicalFilePath.Replace (HttpRuntime.AppDomainAppPath, "/").Replace (Path.DirectorySeparatorChar, '/');

No comments: