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

  • 相关阅读:
    c# netcore 发送http请求并接收返回数据
    CentOS7 nginx安装与卸载
    c# 取出特定标签的内容 去除html标签
    dotnet运行项目
    hangfire自定义访问api接口
    10万个数中取最大的10个数
    指定的服务已标记为删除
    gitlab-配置邮件
    gitlab-centos的安装
    ansible-任务控制tags
  • 原文地址:https://www.cnblogs.com/sueris/p/6432696.html
Copyright © 2011-2022 走看看