我有一個觀點在這裏我把事件的ID,然後我可以下載所有該事件的圖片..... 這裏是我的代碼ASP MVC下載Zip文件
[HttpPost]
public ActionResult Index(FormCollection All)
{
try
{
var context = new MyEntities();
var Im = (from p in context.Event_Photos
where p.Event_Id == 1332
select p.Event_Photo);
Response.Clear();
var downloadFileName = string.Format("YourDownload-{0}.zip", DateTime.Now.ToString("yyyy-MM-dd-HH_mm_ss"));
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=" + downloadFileName);
using (ZipFile zipFile = new ZipFile())
{
zipFile.AddDirectoryByName("Files");
foreach (var userPicture in Im)
{
zipFile.AddFile(Server.MapPath(@"\") + userPicture.Remove(0, 1), "Files");
}
zipFile.Save(Response.OutputStream);
//Response.Close();
}
return View();
}
catch (Exception ex)
{
return View();
}
}
的問題是,每次我得到的HTML頁面下載,而不是下載「Album.zip」我得到「Album.html」任何想法?
調試如果'downloadFileName'包含'.zip'擴展.. – 2013-03-13 13:01:19
它包含的.zip 這裏是它是什麼「YourDownload-2013-03-13-15_04_20.zip」 – 2013-03-13 13:06:00