简体   繁体   English

获得相对路径的绝对路径

[英]Get absolute path of relative path

I am calling a method in C# as follows: 我在C#中调用一个方法如下:

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

The thing is that the path can be different depending on what folder I am calling RenderChartHTML from. 问题是路径可能会有所不同,具体取决于我从哪个文件夹调用RenderChartHTML。

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);

Use ResolveUrl() . 使用ResolveUrl() It converts a URL into one that is usable on the requesting client. 它将URL转换为可在请求客户端上使用的URL。

So Try this instead : 所以试试这个:

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

Hope this will help !! 希望这会有所帮助!!

You don't need the ~/ . 你不需要~/ Just HttpContext.Current.Server.MapPath("Charts/MSLine.swf"); 只是HttpContext.Current.Server.MapPath("Charts/MSLine.swf");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM