Click here to Skip to main content
15,887,966 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello All

When zipping files m getting the following error...

The archive is either in unknown format or damaged when zipping a file in asp.net

Any Suggestions?
Posted
Comments
Sergey Alexandrovich Kryukov 1-Oct-12 0:30am    
Hardly. There can be too many ways to screw up things. We have no idea which one do you prefer :-)
--SA
cunny 1-Oct-12 1:44am    
protected void btn_downloaddocuments_Click(object sender, EventArgs e)
{

//ExportFunction();
var filePath = string.Empty;
var fileLocation = string.Empty;

//string downloadFileName = "Files.zip";

Response.ContentType = "application/octet-stream";

Response.ContentType = "application/download";




Response.AddHeader("Content-Disposition", "attachment; filename=DownloadedFile.zip");

//Content-Transfer-Encoding: base64
Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.Charset = "";
// Response.AddHeader("content-disposition", "filename=" + downloadFileName);
var ms = new MemoryStream();
var fileLocation1 = "";
using (ZipFile zip = new ZipFile())
{

foreach (GridViewRow row in gvdownloaddocuments.Rows)
{


CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
//if (cb != null && cb.Checked)
//{
filePath = (row.FindControl("lblFileName") as Label).Text;
fileLocation = Server.MapPath("~/Document Images/" + filePath);




// zip.AddFile(fileLocation);
zip.AddFile(fileLocation, @"\Document Images");
// zip.AddFile(fileLocation);

fileLocation1 = Server.MapPath("~/Document Images/" + "DownloadedFiles");


}

zip.Save(fileLocation1 + ".zip");


// zip.Save(fileLocation1 + ".zip");
// zip.Save(Response.OutputStream);
ms.Position = 0;
ms.CopyTo(Response.OutputStream);
//Response.End();
// Response.End();

// Response.Close();



}
HttpContext.Current.Response.End();
// Response.End();

//Response.Close();


}

...This is the code which i have used so far..But when i zip any file..it is throwing a error like...(The-archive-is-either-in-unknown-format-or-damaged)
Rockstar_ 1-Oct-12 2:02am    
filelocations1 variable does not contains a particular file name or foldername. this is the reason it is throwing an exception.Try to give a particular filename or foldername with location.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900