zoukankan      html  css  js  c++  java
  • 文件上传下载

    上传
    1           File.PostedFile.ContentLength //判断文件大小
    2           File.PostedFile.FileName  //文件名称
    3           File.PostedFile.ContentType  //文件类型
    4           Server.MapPath()  //服务器路径对应物理路径
    5           Directory.Exists(pathfile)  //验证文件夹是否存在
    6           Directory.CreateDirectory(pathfile); //创建文件夹
    7           url=pathfile+"1234567"+".ContentType";
    8           file.PostedFile.SaveAs(url);   //保存到文件夹
    View Code
    下载
    1  Response.ContentType="application/x-zip-compressed"; // 下载zip类型
    2         Response.AddHeader("Content-Disposition","attachment;filename=z.zip"); //以xx方式下载 attachment 附件
    3         string filePath =  Server.MapPath("服务器路径")  //服务器路径对应物理路径
    4         Response.TransmitFile(fileName); //下载
    View Code
    循环下载
     1  
     2         string filePath = Server.MapPath("服务器路径");
     3         System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);
     4 
     5         if (fileInfo.Exists == true)
     6         {
     7                 const long readSize = 102400;
     8                 byte[] buffer = new byte[readSize];
     9                 Response.Clear();
    10                 System.IO.FileStream stram= System.IO.File.OpenRead(filePath);
    11                 long allszie = stram.Length;//获取下载的文件总大小
    12                 Response.ContentType = "application/octet-stream";
    13                 Response.AddHeader("Content-Disposition", "attachment; filename=" + "filename.xx");
    14                 while (allszie > 0 && Response.IsClientConnected)
    15                 {
    16                     int lengthRead = iStream.Read(buffer, 0, Convert.ToInt32(readSize));//读取的大小
    17                     Response.OutputStream.Write(buffer, 0, lengthRead);
    18                     Response.Flush();
    19                     allszie = allszie - lengthRead;
    20                 }
    21               Response.Close();
    22         }
    View Code
    Excel转DataSet   
    string str = "Provider=Microsoft.Ace.OLEDB.12.0;" + "data source=" + savePath + ";Extended Properties='Excel 12.0; HDR=Yes; IMEX=1'";    
     1 OleDbConnection conn= new OleDbConnection(strcon);
     2      try
     3      {
     4          string strsql = string.Format("SELECT * FROM  Sheet1$");
     5          conn.Open();
     6          OleDbDataAdapter command= new OleDbDataAdapter(strsql, conn);
     7          DataSet ds = new DataSet();
     8          command.Fill(ds, "[" + tableName + "$]");
     9          excelConn.Close();       
    10          return ds;
    View Code
  • 相关阅读:
    DockerFile 解析
    Docker 容器数据卷
    Docker 镜像
    Docker 常用命令
    Docker 安装
    vue全站式笔记
    接口环境配置
    前端跨域的三种方式
    vue+axios 模拟后台返回数据的三种方式:本地创建json、easymock平台、mockjs
    cookie、sessionStorage与localStorage是什么?
  • 原文地址:https://www.cnblogs.com/Evaniko/p/6427514.html
Copyright © 2011-2022 走看看