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("表单编号异常");
                }
            }

  • 相关阅读:
    ps基础磨皮(混入了奇怪的博客~)
    spring boot配置ssl
    Chrome自动翻译失效的解决办法
    小红书数美滑块验证码
    使用DataLoader报错AttributeError: 'int' object has no attribute 'numel'
    glidedsky-爬虫-验证码-1
    glidedsky-爬虫-雪碧图-2
    glidedsky-爬虫-雪碧图-1
    glidedsky-爬虫-CSS反爬
    glidedsky-爬虫-字体反爬-1
  • 原文地址:https://www.cnblogs.com/sueris/p/6432696.html
Copyright © 2011-2022 走看看