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>");
                                      }


          posted on 2014-04-03 10:59 Ying-er 閱讀(315) 評論(0)  編輯  收藏 所屬分類: .Net
          主站蜘蛛池模板: 青神县| 佛坪县| 桦南县| 鄂伦春自治旗| 当雄县| 新民市| 资溪县| 南雄市| 博兴县| 内江市| 沅陵县| 进贤县| 克山县| 新平| 江川县| 丹阳市| 金坛市| 施秉县| 东乡县| 鹤庆县| 灌云县| 祁阳县| 张掖市| 宜黄县| 紫金县| 东乌珠穆沁旗| 葵青区| 达拉特旗| 屯昌县| 青铜峡市| 外汇| 射阳县| 靖宇县| 泗洪县| 赤峰市| 循化| 桐乡市| 佳木斯市| 精河县| 博白县| 开封县|