MVC4 打包zip文件

MVC4 打包zip文件
using ICSharpCode.SharpZipLib.Zip;

try
                            {
                                 string zipName = "農地基本台帳"+Session.SessionID + DateTime.Now.Ticks.ToString()+".zip";
                                 string zipFilePath = Server.MapPath("~/App_Data/Nouka/Download/") + zipName;
                                 using (ZipOutputStream s =  new ZipOutputStream(System.IO.File.Create(zipFilePath)))
                                {
                                    s.SetLevel(9);
                                     byte[] buffer =  new  byte[4096];
                                     for ( int i = 0; i < list.Count; i++)
                                    {
                                         string filename = excelNoutikihondaichou(list[i].農家番号);
                                         string path = Server.MapPath("~/App_Data/Nouka/Download/") + filename;
                                         string name = filename.Substring(0, filename.LastIndexOf("農地基本台帳")) + "農地基本台帳.xls";

                                        ZipEntry entry =  new ZipEntry(name);
                                        entry.DateTime = DateTime.Now;
                                        s.PutNextEntry(entry);
                                         using (FileStream fs = System.IO.File.OpenRead(path))
                                        {
                                             int sourceBytes;
                                             do
                                            {
                                                sourceBytes = fs.Read(buffer, 0, buffer.Length);
                                                s.Write(buffer, 0, sourceBytes);
                                            }  while (sourceBytes > 0);
                                        }
                                    }
                                    s.Finish();
                                    s.Close();
                                     return Content("<script type='text/javascript'>nouka.excelNoukaIkkatu.doDownload({desc:'"+zipName+"'})</script>");
                                }
                            }
                             catch
                            {
                                 return Content("<script type='text/javascript'>nouka.excelNoukaIkkatu.doDownload({desc:'NaN'})</script>");
                            }



你可能感兴趣的:(MVC4 打包zip文件)