在我的asp.net网页中,我有一个Grid
和一个下载Button
。 Grid
填充有关共享位置文件的信息,下载按钮会在压缩后下载所有文件。
我使用Ionic.Zip
库进行压缩。
以下是代码,在用户点击下载按钮时执行。
下载工作正常,但是当我将文件信息(如名称等)绑定到GridView
控件时,它会在将文件信息绑定到GridView
控件后中断。
我收到错误"压缩的zip文件夹无效",但是当我使用Ionic.Zip
库保存zip文件时,它没有损坏,我可以手动打开它!
HttpContext.Current.Response.Clear();
Response.ClearContent();Response.Clear();string LogPath = ConfigurationManager.AppSettings["LogPath"];
LogPath = Path.Combine(LogPath, Application);
//Zip File will be created when one of the file is in use during Zip.
ZipFile Zip = new ZipFile();
Zip.AddDirectory(LogPath);
string _DateTime = System.DateTime.Now.ToString("ddMMyyHHmmssfff");
string ZipFileName = string.Format("ZipFile{0}.zip",_DateTime);
//Zip.Save(Response.OutputStream);
ErrorMessage.Text = Response.OutputStream.CanRead + " " + Response.OutputStream.CanWrite;
string _Path = MapPath(".");
_Path = Path.Combine(_Path, ZipFileName);
ErrorMessage.Visible = true;
Zip.Save(_Path);
// Response.AppendHeader("content-disposition", "filename=" + ZipFileName);
Response.AppendHeader("content-disposition", "attachment; filename=" + ZipFileName);
//Response.ContentType = "application/zip";
Response.ContentType = "application/unknown";
Response.WriteFile(_Path);