[英]How to generate absolute path from physical path in WebAPI Controller
In a WebAPI Controller, how to return the absolute or relative path to a file giving that I only know the full physical file path? 在WebAPI控制器中,如何返回文件的绝对路径或相对路径,从而只知道完整的物理文件路径?
I found a lot of information for the opposite using System.Web.Hosting.HostingEnvironment.MapPath, but I need the opposite (from physical to absolute/relative). 我使用System.Web.Hosting.HostingEnvironment.MapPath找到了很多相反的信息,但我需要相反的(从物理到绝对/相对)。
Is this the best way of doing it?: 这是最好的方式吗?:
Url.Content("~/" + myFullPath.Replace(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath,""))
您可以从文件的物理路径中删除ApplicationPhysicalPath
属性的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.