zoukankan      html  css  js  c++  java
  • 文件批量下载到本地

    1. 添加dll库DotNetZip

    public ActionResult DownloadFile(string documentno)
            {
                if (!string.IsNullOrEmpty(documentno))
                {
                    var list =
                        _borrowerContractImageRepository.GetAlList(documentno);
                    if (list.Count > 0)
                    {
                        //获取服务器中的文件路径
                        string filePath =Configs.GetFileSite();

                        //压缩后的文件存放路径
                        string destFile = @"E:文件" + documentno + @"";
                        if (!Directory.Exists(destFile))//判断文件夹是否存在
                        {
                            Directory.CreateDirectory(destFile);//不存在则创建文件夹
                        }
                        using (ZipFile zip = new ZipFile(System.Text.Encoding.Default))
                        {
                            //单个文件下载,不需要打包
                            foreach (var fileName in list)
                            {
                                WebClient wc=new WebClient();  
                                wc.DownloadFile(filePath + fileName,destFile+Path.GetFileName(fileName));
                                zip.AddFile(destFile + Path.GetFileName(fileName), "Images");

                            }
                            zip.Save(Server.MapPath("~/ZIP/"+documentno+".zip"));
                        }
                        
                        return File(Server.MapPath("~/ZIP/"+documentno + ".zip"),
                                                   "application/zip", documentno+".zip");
                    }
                    else
                    {
                        return Content("没有文件可以下载");
                    }
                }
                else
                {
                    return Content("表单编号异常");
                }
            }

  • 相关阅读:
    Oracle面试题目及解答
    java -jar Incompatible argument to function
    plsql 查询到别的用户下面的表
    redis数据类型[string 、list 、 set 、sorted set 、hash]
    redis-cli 常用命令
    js判断浏览器,包括Edge浏览器
    HTMl5的sessionStorage和localStorage
    JS实现密码加密
    sprintf.js
    js-crc32
  • 原文地址:https://www.cnblogs.com/sueris/p/6432696.html
Copyright © 2011-2022 走看看