首页 > 解决方案 > 如何使用 Server.MapPath 将文件上传到映射在我的计算机上的服务器

问题描述

到目前为止,我知道如何使用下面的代码将文件上传到我的解决方案中的文件夹。

string root = HttpContext.Current.Server.MapPath("~/upload");

如何将文件保存到不在解决方案中的其他位置,即保存到映射到我的电脑的服务器位置。

string root = HttpContext.Current.Server.MapPath("/Z:/UploadFolder"); I have tried this but its not saving to the server so where I am going wrong?

标签: c#asp.net-mvcfile-uploadknockout.jsserver.mappath

解决方案


MapPath当你有一个相对路径并且想要使用你的项目的路径时,你应该使用它。对于您不需要的另一条路径MapPath。像这样使用它:

string root ="Z:\\UploadFolder";

推荐阅读