简体   繁体   中英

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?

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

Is this the best way of doing it?:

Url.Content("~/" + myFullPath.Replace(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath,""))

您可以从文件的物理路径中删除ApplicationPhysicalPath属性的值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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