德才手游网:十大热门手游排行榜2023前十名,十大热门手机应用排行榜2023前十名,让你Get最新手游应用、分享你的热辣点评。
网站地图
你的位置: 首页 > 游戏资讯 > 操作系统

ASP.NET下文件批量下载应用

  • 2023-04-01 05:25:31
  • 来源:网络
  • 在手机上看

    扫一扫立即进入手机端

  1.场景描述

  在B/S环境下,客户提出批量导出员工照片功能。具体为:选中一个部门或者单位,系统能够批量下载所选单元的照片,下载到用户客户端。

  2.解决思路

  由于系统中员工的照片存储在服务器硬盘上,因此,应该有两种方式供用户选择:其一,写一个C/S客户端,利用客户端功能,实现客户端批量下载操作。其二,在现有ASP.NET环境下,将所需照片文件合并成一个文件下载到用户客户端。比较而言,两种思路的难度都不大,但是考虑到系统的统一性,最终决定采用方案二,将文件打包后下载。

  3.实现步骤

  在用户操作界面,由用户选择员工,系统根据所选人员,在服务器上创建用于存储所选文件的临时文件夹,将所选文件拷贝至临时文件夹。然后调用RAR程序,对临时文件夹进行压缩,然后输出到客户端。最后删除临时文件夹。

  4.部分关键代码

  创建临时文件夹

  string Folder = DateTime.Now.ToString(“HHMMss“);

  string tempFolder = Path.Combine(ImagesPath, Folder);

  Directory.CreateDirectory(tempFolder);

  var empList = rs.ToList();

  拷贝照片文件

  foreach (var x in empList)

  {

  File.Copy(ImagesPath + @“\“ + x.ID + “.jpg“, tempFolder + @“\“ + x.DeptName + “-“ + x.Name + “-“ + x.ID + “.jpg“);

  }

  产生RAR文件,及文件输出

  RARsave(tempFolder, tempFolder, Folder);

  ResponseFile(tempFolder + @“\“ + Folder + “.rar“);

  public void RARsave(string patch, string rarPatch, string rarName)

  {

  String the_rar;

  RegistryKey the_Reg;

  Object the_Obj;

  String the_Info;

  ProcessStartInfo the_StartInfo;

  Process the_Process;

  try

  {

  the_Reg = Registry.ClassesRoot.OpenSubKey(@“winrar“);

  the_Obj = the_Reg.GetValue(““);

  the_rar = the_Obj.ToString();

  the_Reg.Close();

  the_rar = the_rar.Substring(1, the_rar.Length - 7);

  Directory.CreateDirectory(patch);

  //命令参数

  //the_Info = “ a “ + rarName + “ “ + @“C:Test?70821.txt“; //文件压缩

  the_Info = “ a “ + rarName + “ “ + patch + “ -r“;

  the_StartInfo = new ProcessStartInfo();

  the_StartInfo.FileName = “WinRar“;//the_rar;

  the_StartInfo.Arguments = the_Info;

  the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

  //打包文件存放目录

  the_StartInfo.WorkingDirectory = rarPatch;

  the_Process = new Process();

  the_Process.StartInfo = the_StartInfo;

  the_Process.Start();

  the_Process.WaitForExit();

  the_Process.Close();

  }

  catch (Exception ex)

  {

  throw ex;

  }

  }

  protected void ResponseFile(string fileName)

  {

  FileInfo fileInfo = new FileInfo(fileName);

  Response.Clear();

  Response.ClearContent();

  Response.ClearHeaders();

  Response.AddHeader(“Content-Disposition“, “attachment;filename=“ + fileName);

  Response.AddHeader(“Content-Length“, fileInfo.Length.ToString());

  Response.AddHeader(“Content-Transfer-Encoding“, “binary“);

  Response.ContentType = “application/octet-stream“;

  Response.ContentEncoding = System.Text.Encoding.GetEncoding(“gb2312“);

  Response.WriteFile(fileInfo.FullName);

  Response.Flush();

  string tempPath = fileName.Substring(0, fileName.LastIndexOf(“\\“));

  DelDir(tempPath);

  Directory.Delete(tempPath);

  Response.End();

  }

游戏推荐

epic幸福工厂中文怎么设置(幸福工厂epic存档文件在哪) 暗区突围情报文件在哪(暗区突围情报在哪里刷新) 《网盘》怎么设置密码呢(网盘怎么给文件夹设密码) apex英雄缺少文件怎么办(apex文件缺失) steam无法验证游戏会话(steam无法验证游戏文件) 《星球工匠》文件保存位置怎么改(星球工厂在哪) excel表格自动保存在哪里(excel表格自动保存的文件在哪里) apex配置文件详解(apex配置设置) uc浏览器如何设置mp4格式(uc浏览器如何设置mp4格式文件) 应该如何处理TMP格式文件保证系统安全 应用 LINUX下文件字符集编码转换 Windows文件损坏 Windows文件损坏?一条命令就搞定 linux用户tab自动补齐文件名 Linux文件夹 查看Linux文件夹下所有文件的总大小 文件 新手看招:在Linux操作系统下创建锁文件 etc下的passwd和shadow文件详解 pscp命令linux文件上传与下载 MKV文件用什么播放器播放?MKV是什么格式的详细介绍
更多

手机游戏排行榜