|
我的代码:
string zipFileName = DateTime.Now.Ticks.ToString() + ".zip";
var FileNames = RowsAreSelected(Grid1, "FileNames", 0);
string[] FileArr = FileNames.Split(',');
List<string> files = new List<string>();
for (int i = 0; i < FileArr.Length; i++)
{
files.Add(FileArr[i].Substring(1, FileArr[i].Length - 2));
}
using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(Encoding.UTF8))//解决中文乱码问题
{
foreach (var item in files)
{
zip.AddFile(Server.MapPath(string.Format("~/download/jcxxcj/{0}", item)), "");
}
zip.Save(Server.MapPath("~/download/jcxxcjzip/" + zipFileName));
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(zipFileName, System.Text.Encoding.UTF8));
FileStream fs = File.OpenRead(Server.MapPath("~/download/jcxxcjzip/" + zipFileName));
//定义缓冲区大小
byte[] buffer = new byte[10240000];
//第一次读取
int i = 0;
double filelength = fs.Length;
while (filelength > 0)
{
i = fs.Read(buffer, 0, buffer.Length);
Response.OutputStream.Write(buffer, 0, i);
filelength = filelength - i;
}
//关闭磁盘文件流
fs.Close();
//关闭输出流
Response.End();
}
}
错误截图:
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|