首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

asp.net 批量下载,该如何解决

2013-06-19 
asp.net 批量下载如何在选择多个文件批量下载 打包文件中有多个文件呢? 现在我的rar文件中就一个文件夹[解

asp.net 批量下载
如何在选择多个文件批量下载 打包文件中有多个文件呢? 现在我的rar文件中就一个文件夹
[解决办法]
就是先压缩后下载,多个文件压缩成一个文件
[解决办法]
先压缩,在下载!
在程序中先引用ICSharpCode.SharpZipLib.dll 压缩文件的DLL


#region   压缩文件夹
                     try
                     {
                         string[] filenames = Directory.GetFiles(derctoryinfo.FullName);

                         if (filenames.Length <= 0)
                         {
                             JScript.Alert("在指定路径下未找到符合的影像文件!");
                             return;
                         }
                             using (ZipOutputStream zipoutput = new ZipOutputStream(File.Create(derctoryinfo.FullName + ".Zip")))
                             {
                                 //zipoutput.SetLevel(10);
                                 byte[] buffer = new byte[4096];

                                 foreach (string file in filenames)
                                 {
                                     ZipEntry entry = new ZipEntry(Path.GetFileName(file));
                                     entry.DateTime = DateTime.Now;


                                     zipoutput.PutNextEntry(entry);
                                     using (FileStream fs = File.OpenRead(file))
                                     {
                                         int sourcebytes;
                                         do
                                         {
                                             sourcebytes = fs.Read(buffer, 0, buffer.Length);
                                             zipoutput.Write(buffer, 0, sourcebytes);
                                         } while (sourcebytes > 0);
                                     }
                                 }

                                 zipoutput.Finish();
                                 zipoutput.Close();
                             }
                         
                         
                     }
                     catch (Exception ex)


                     {

                         throw ex;
                     }
                                         //实现下载功能
                    System.IO.FileInfo downfile = new System.IO.FileInfo(derctoryinfo.FullName + ".zip");
                     Response.Clear();
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(derctoryinfo.Name + ".zip"));
                   Response.AddHeader("Content-Length", downfile.Length.ToString());
                   Response.ContentType = "application/octet-stream";
                     Response.WriteFile(downfile.FullName);
                    Response.Flush();
                     Response.Clear();
                    Response.End();
               }
                     #endregion

这是一个压缩文件,并实现下载的主要代码,希望对你有帮助
[解决办法]
http://www.189works.com/article-85033-1.html
[解决办法]
http://www.189works.com/article-85033-1.html 

热点排行