Skip to main content
 首页 » 编程设计

c#之mvc web api中文件的真实物理路径

2024年06月03日44soundcode

我正在使用 MVC 网络 API 构建示例应用程序。我从 POST 请求中获取文件名。如果我使用下面的代码获取文件的物理路径,它将返回应用程序文件夹的路径而不是我其他驱动器(比如 D: 驱动器)中的文件路径

HttpContext.Current.Server.MapPath("/~" + fileName); 

请您参考如下方法:

请使用下面的语句

HttpContext.Current.Request.PhysicalApplicationPath + "/" + fileName