0

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.

शेखर
  • 17,412
  • 13
  • 61
  • 117
maxp
  • 24,209
  • 39
  • 123
  • 201

2 Answers2

1
string pathFROM = Server.MapPath("~/MYSITE/css/reset.css");
Andrew Paes
  • 1,940
  • 1
  • 15
  • 20
0

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)
Kuzgun
  • 4,649
  • 4
  • 34
  • 48