【发布时间】:2011-05-26 13:29:24
【问题描述】:
在调试/测试时,我一直在尝试将传入的上传图像保存在我的开发机器上的 ~/Content 中,但那里没有传输任何文件。该文件夹是否允许将图像保存/传输到它,还是我需要将它们保存在 ~/App_Data 中?
编辑:我正在使用的代码:
public ActionResult(AdminGameEditModel formData)
{
Game game = new Game();
AutoMapper.Mapper.Map<AdminGameEditModel, Game>(formData, game);
if (formData.BoxArt.ContentLength > 0 && formData.IndexImage.ContentLength > 0)
{
var BoxArtName = Path.GetFileName(formData.BoxArt.FileName);
var BoxArtPath = Path.Combine(Server.MapPath("~/Content/Images/BoxArt"), BoxArtName);
game.BoxArtPath = BoxArtPath;
formData.BoxArt.SaveAs(BoxArtPath);
var IndexImageName = Path.GetFileName(formData.IndexImage.FileName);
var IndexImagePath = Path.Combine(Server.MapPath("~/Content/Images/GameIndexImages"), IndexImageName);
game.IndexImagePath = IndexImagePath;
formData.IndexImage.SaveAs(IndexImagePath);
}
// rest of controller method
}
两个文件都是HttpPostedFileBase 对象。我目前使用的服务器只是在VS调试期间运行的ASP.NET服务器。
【问题讨论】:
标签: c# asp.net-mvc-2 file-upload appdata