Get the absolute path of the relative path

I call the method in C # as follows:

return Chart.RenderChartHTML("../../Charts/MSLine.swf"); 

The fact is that the path may be different depending on which folder I call RenderChartHTML from.

I tried the following to find the absolute path, but it does not work:

 string mslinepath = HttpContext.Current.Server.MapPath("~/Charts/MSLine.swf"); return Chart.RenderChartHTML(mslinepath); 
+4
source share
2 answers

Use ResolveUrl () . It converts the URL into one that can be used on the requesting client.

So try instead:

 string mslinepath = ResolveUrl("~/Charts/MSLine.swf") 

Hope this helps!

+8
source

You do not need ~/ . Just HttpContext.Current.Server.MapPath("Charts/MSLine.swf");

+7
source

Source: https://habr.com/ru/post/1444632/


All Articles