问题描述
发布后正在下载单个文件。但是在发布asp.net项目后,将所有文件作为zip文件下载不起作用。
建议我解决方案
我尝试过:
如果我添加Ionic.Zip.dll则无法正常工作。所以我使用了NuGet软件包DotNetZip
但是在发布项目后它没有工作。
我的代码是,使用Ionic.Zip
;
ZipFile zip = new ZipFile();
if(dt.Rows.Count> 0)
{
foreach(DataRow dr in dt.Rows)
{
zip.AddEntry(dr [Name]。ToString() ,dr [Data]。ToString());
}
}
var zipMs = new MemoryStream();
zip.Save(zipMs);
byte [] fileData = zipMs.GetBuffer();
zipMs.Seek(0,SeekOrigin.Begin);
zipMs.Flush();
Response.Clear();
Response.AddHeader(content-disposition,attachment; filename = docs.zip);
Response.ContentType =application / zip;
Response.BinaryWrite(fileData);
响应。结束();
Downloading single file is working after publishing. But downloading the all the files as zip file is not working after publishing asp.net project.
Suggest me solution
What I have tried:
If I add Ionic.Zip.dll it is not working. So I used NuGet package DotNetZip
But it is not working after publishing the project.
My code is,
using Ionic.Zip;
ZipFile zip = new ZipFile();
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
zip.AddEntry(dr["Name"].ToString(), dr["Data"].ToString());
}
}
var zipMs = new MemoryStream();
zip.Save(zipMs);
byte[] fileData = zipMs.GetBuffer();
zipMs.Seek(0, SeekOrigin.Begin);
zipMs.Flush();
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=docs.zip ");
Response.ContentType = "application/zip";
Response.BinaryWrite(fileData);
Response.End();
推荐答案
这篇关于发布ASP.NET项目后,Zip文件无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!