12 Mar 2009

Resolve Virtual Path From Physical Path (ASP.NET)

Quick code snippet to help people who want to derive a Virtual (web) path from a Physical (file) path:

string strVirtualPath = VirtualPathUtility.ToAbsolute("~/" + strPhysicalPath.Replace(Request.PhysicalApplicationPath, "").Replace("\\", "/"));

VirtualPathUtility FTW!

No comments:

Post a Comment

Comments are very welcome but are moderated to prevent spam.

If I helped you out today, you can buy me a beer below. Cheers!