如何使用asp.net Web表单将多个文件保存为单个zip文件

时间:2017-07-04 10:55:34

标签: c# asp.net gridview

如何使用asp.net web表单将多个文件保存到单个zip中,实际上我将基于注册ID的Gridview按钮中的文件下载到zip中。我无法将两个或多个文件添加到zip中。一个文件正在正确下载,当我将第二个文件添加到zip时没有任何逻辑。

正确下载单个文件。

zip.AddFile(LatterAcceptance,"My folder");

当我将另外一个文件添加到zip

zip.AddFile((LatterAcceptance,HighestDegree),"My folder");

但是,如果我将另一个文件添加到像HighestDegree这样的zip中,会收到以下错误:

  

无法将lambda表达式转换为'string'类型,因为它不是委托类型

以下是我的c#代码。

    ZipFile zip = new ZipFile();
    DataTable dt = new DataTable();
    LinkButton Type = sender as LinkButton;
    GridViewRow grow = (GridViewRow)Type.NamingContainer;
    string RegistrationId = gv_TotalAllReg.DataKeys[grow.RowIndex].Values[0].ToString();

    bo.Para1 = RegistrationId;//RegId;
    bo.Para2 = "3";//Paravalue
    dt = bl.Admin_Get_UserInformation(bo);

    foreach(DataRow row in dt.Rows)
   {
        string LA = row["LatterAcceptance"].ToString();
        string LatterAcceptance = Server.MapPath("~/LatterAcceptance/" + LA);

        string HD = row["HighestDegree"].ToString();
        string HighestDegree = Server.MapPath("~/HighestDegree/" + HD);


        zip.AddFile(LatterAcceptance,"My folder");
   }

    Response.Clear();
    Response.BufferOutput = false;
    string zipName = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MM-dd-HHmmss"));
    Response.ContentType = "application/zip";
    Response.AddHeader("content-disposition", "attachment;fileName=" + zipName);
    zip.Save(Response.OutputStream);
    Response.End(); 

1 个答案:

答案 0 :(得分:1)

您正在使用DotNetZip库。阅读documentation可能会有所帮助。

您会找到以下内容:

 <mobile>
 <webview>
 <start>https://secure.innovatepayments.com/gateway/webview_start.html? code=f1caa6ce6c23595b71dc00369</start>   
<close>https://secure.innovatepayments.com/gateway/webview_close.html</close>
<abort>https://secure.innovatepayments.com/gateway/webview_abort.html</abort>
<code>f1caa6ce6c23595b71dc00369</code>
</webview>
<trace>40008/1683846/595b7168dc</trace>
</mobile>

您需要为要添加到ZIP的每个文件执行using (ZipFile zip = new ZipFile()) { // add this map file into the "images" directory in the zip archive zip.AddFile("c:\\images\\personal\\7440-N49th.png", "images"); // add the report into a different directory in the archive zip.AddFile("c:\\Reports\\2008-Regional-Sales-Report.pdf", "files"); zip.AddFile("ReadMe.txt"); zip.Save("MyZipFile.zip"); }