我有一个 web api,例如:
[Route("api/fileupload/{name}")]
public string GetFileWithExtension(string name)
{ private readonly string _recipientsExcelFilesPath = System.Web.Hosting.HostingEnvironment.MapPath(
WebConfigurationManager.AppSettings["RecipientsExcelFiles"]);
// _recipientsExcelFilesPath gives absolute URL to the directory
// name property is a name of file
// I would like here get absoulute url + path
**C:\Code\MyProject\Project.WebApi\Data\MyExcelFiles.xlsx**
}
因此,基本上,此方法采用文件名,并应返回保存在本地系统 + 扩展名上的该文件的完整路径。
在 web api 配置中,我有类似的东西:
<appSettings>
<add key="RecipientsExcelFiles" value="~\\Data\\RecipientsExcelFiles\\" />
</appSettings>