簡體   English   中英

將文檔轉換為zip文件,添加文件並下載,但是在打開時出現錯誤

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

  1. 成功將文檔添加到zip中,添加條目並下載它。

  2. 但是在打開例如Doc1,Doc2時,如果我僅下載doc1(下載並查看成功)

  3. 如果我嘗試下載它的doc2,但是在打開時(無法打開文件,它似乎不是有效的檔案,請再試一次,這是打開時的消息)。 如果我同時檢查並下載,並且下載成功,則可以將其打開。

任何幫助,不勝感激

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();

我通過使用解決了

using ICSharpCode.SharpZipLib.Zip;

通過使用(使用Ionic.Zip;)此數據在內部損壞,甚至不引發異常

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM