Nate Pet
Nate Pet

Reputation: 46322

Get absolute path of relative path

I am calling a method in C# as follows:

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

The thing is that the path can be different depending on what folder I am calling RenderChartHTML from.

I tried the following so that it finds the absolute path but not working:

string mslinepath = HttpContext.Current.Server.MapPath("~/Charts/MSLine.swf");

return Chart.RenderChartHTML(mslinepath);

Upvotes: 3

Views: 23065

Answers (2)

Kundan Singh Chouhan
Kundan Singh Chouhan

Reputation: 14302

Use ResolveUrl(). It converts a URL into one that is usable on the requesting client.

So Try this instead :

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

Hope this will help !!

Upvotes: 7

Ray Cheng
Ray Cheng

Reputation: 12586

You don't need the ~/. Just HttpContext.Current.Server.MapPath("Charts/MSLine.swf");

Upvotes: 7

Related Questions