Getting error file corrupt error when downloading large files using Ionic.zip in c#. When user extracts that file file corrupt is being shown. When i am doing same with smaller no of files than it is working fine. Even it is not giving any error while creating zip files. I am creating zip file of existing pdf files which are added in one zip files. There may be 5 files or may 1000 files of minimum 10 MB each.
I have tried with threshold and all other options provided on google, but didn't find any solutions.
using (ZipFile zip = new ZipFile())
{
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.Level9;
//zip.AddDirectoryByName("Files");
for (int i = 0; i < dt.Rows.Count; i++)
{
filePath = Convert.ToString(dt.Rows[i]["filePath"]);
fileIds.Add(Convert.ToInt32(dt.Rows[i]["fileid"]));
string fileFullName = Convert.ToString(dt.Rows[i]["fileName"]);
string fName = Convert.ToString(dt.Rows[i]["fileName"]).Split('_')[1];
//ExceptionLogging c1 = new ExceptionLogging("filePath = " + filePath + " fileFullName = " + fileFullName +
// " fName = " + fName);
//c1.ErrorLog(HttpContext.Current.ApplicationInstance.Server.MapPath("~/Logs/"));
if (!fileNamesList.Contains(fileFullName.Split('_')[0]))
{
//ExceptionLogging c2 = new ExceptionLogging("In if condition -- filePath = " + filePath);
//c2.ErrorLog(HttpContext.Current.ApplicationInstance.Server.MapPath("~/Logs/"));
zip.AddFile(filePath, "Files");
fileNamesList.Add(fileFullName.Split('_')[0]);
}
else
{
filePath = filePath.Substring(0, filePath.Length - 4) + "_" + fName;
//filePath = filePath.Split('.')[0] + "_" + fName;
zip.AddFile(filePath, "Files");
fileNamesList.Add(fileFullName);
//ExceptionLogging c3 = new ExceptionLogging("In else condition -- filePath = " + filePath + " fileFullName = " + fileFullName);
//c3.ErrorLog(HttpContext.Current.ApplicationInstance.Server.MapPath("~/Logs/"));
}
//zip.AddFile(filePath, "Files");
}
Response.Clear();
Response.BufferOutput = false;
string zipName = String.Format("ZipFile-{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
zip.Save(Response.OutputStream);
//Response.End();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
I should be able to download large files inside zip.