【发布时间】:2014-01-20 02:14:49
【问题描述】:
我想上传图片到服务器,但是图片可以在本地上传到~/images/profile的项目文件夹,但是如果我使用完整路径,它不会上传到服务器。我正在使用的代码在下面给出了一个示例 url。请帮助解决我的问题。我看过stackoverflow的其他链接,但它们不起作用。它给出路径无效的错误消息。虚拟路径和SaveAs方法配置为需要有根路径,且路径没有根。
public ActionResult FileUpload(HttpPostedFileBase file, tbl_Image model)
{
if (file != null)
{
string pic = System.IO.Path.GetFileName(file.FileName);
string path = System.IO.Path.Combine(Server.MapPath("http://sampleApp.com/images/profile/"), pic);
file.SaveAs(path);
db.AddTotbl_Image(new tbl_Image() { imagepath = "http://sampleApp.com/images/profile/" + pic });
db.SaveChanges();
}
return View("FileUploaded", db.tbl_Image.ToList());
}
【问题讨论】:
标签: c# .net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4