Reputation: 25171
I can find lots of .NET functions that convert a virtual path ("~/images/test.jpeg")
to a relative url ("/MYSITE/images/test.jpeg")
, however do any functions exist that convert a Relative Url to a Virtual path?
The alternative is to use something like:
var relativeUrl = "/MYSITE/css/reset.css";
var appPath = System.Web.HttpRuntime.AppDomainAppVirtualPath;
string virtualPath = string.Empty;
if (relativeUrl.IndexOf(appPath, StringComparison.OrdinalIgnoreCase) == 0)
virtualPath = relativeUrl.Substring(appPath.Length);
...
Instead.
Thanks.
Upvotes: 0
Views: 1348
Reputation: 4747
If you are going to use it in asp.net:
string relativeUrl = "/MYSITE/css/reset.css";
string virtualpath= Server.MapPath("/")+relativeUrl.substring(1,relativeUrl.Length-1)
Upvotes: 0