用于下载zip文档的代码无效

时间:2013-08-13 08:21:06

标签: c# zipfile

我写了一个方法来下载zip文件夹中的所有文件。但下载后,当我打开文件时,它给出错误 - “尝试在文件开头之前移动指针。”我正在使用Ionic拉链。守则是 -

 protected void ZipDownload()
    {
        var list = db.Documents.Where(u => u.userId == (int)Session["usrId"]).Select(u => new { u.doc, u.docname, u.doctype });
        ZipFile zip = new ZipFile();
        foreach (var file in list)
        {

            zip.AddEntry(file.docname, (byte[])file.doc.ToArray());
        }
        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();

    }

0 个答案:

没有答案