I am using c#, asp.net and working on a web application.
I initially had a relative path as such which I needed to be an absolute path. The below works but need to get the absolute path:
return Chart.RenderChartHTML("../../Charts/MSLine.swf");
I tried the following which didn't work (note that it gives me the complete path on my hard drive to .swf):
string mslinepath = HttpContext.Current.Server.MapPath("Charts/MSLine.swf");
return Chart.RenderChartHTML(mslinepath);
I then tried the following which works:
string mslinepath = VirtualPathUtility.ToAbsolute("~/Charts/MSLine.swf");
return Chart.RenderChartHTML(mslinepath);
Wondering why VirtualPathUtility.ToAbsolute works while the other one doesn't.
MapPath
returns the physical file path on your server which corresponds to the specified virtual path.
(Eg: "C:\inetpub\wwwroot\Charts\MSLine.swf")
ToAbsolute
converts an app-relative virtual path (one starting with "~/") to an absolute virtual path.
(Eg: "/AppName/Charts/MSLine.swf")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With