maxp
maxp

Reputation: 25171

Relative Url to Virtual Path?

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

Answers (2)

Andrew Paes
Andrew Paes

Reputation: 2022

string pathFROM = Server.MapPath("~/MYSITE/css/reset.css");

Upvotes: 1

Kuzgun
Kuzgun

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

Related Questions