下载文件已损坏asp.net

时间:2016-03-12 16:27:07

标签: c# asp.net

在我的asp.net网页中,我有一个Grid和一个下载ButtonGrid填充有关共享位置文件的信息,下载按钮会在压缩后下载所有文件。

我使用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);

0 个答案:

没有答案