简体   繁体   中英

converting documents to zip file, Added files and downloading, but while opening getting error

  1. Successfully adding documents in to zip add entry and downloading it.

  2. But while opening for example Doc1, Doc2 If i download only doc1 (download and view Successfull)

  3. if i try doc2 it downloaded, but while opening(Cannot open file, It does not appear to be a valid archieve, Try again this is message when opened). If i checked both and downloaded and it's successfully downloaded and I can open it.

Any help greatly appreciated

ZipFile zip = new ZipFile();

foreach (GridDataItem item in RadGridSearchResults.MasterTableView.Items)
{
    int documid;             
    bool chec;
    CheckBox check = (CheckBox)item.FindControl("CheckBox1");
    DocDetails dd = new DocDetails();
    if (check.Checked == true)
    {
        documid = Convert.ToInt32(item["DOCUMENT_ID"].Text);
        Document document = Document.GetDocumentByDocumentId(documid);    
        zip.AddEntry(document.DocumentName, document.DocumentFileImage);

    }                      
}

var zipMs = new MemoryStream();
zip.Save(zipMs);

byte[] fileData = zipMs.GetBuffer();           
zipMs.Seek(0, SeekOrigin.Begin);
zipMs.Flush();

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=docs.zip ");
Response.ContentType = "application/zip";
Response.BinaryWrite(fileData);
Response.End();

I resolved it by using

using ICSharpCode.SharpZipLib.Zip;

by using (using Ionic.Zip;) this data is corrupting internally and not even throwing exception

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM