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 阅读(293) 评论(0)  编辑  收藏 所属分类: .Net

只有注册用户登录后才能发表评论。


网站导航: