zoukankan      html  css  js  c++  java
  • .net 文件点击直接下载函数 记录

    void down(string filepath)
            {
                //确定文件的物理路径
                string filePath = Server.MapPath(filepath);
                FileInfo Fi = new FileInfo(filePath);
                if (Fi.Exists)
                {
                    FileStream fs = new FileStream(filePath, FileMode.Open);
                    byte[] bytes = new byte[(int)fs.Length];
                    fs.Read(bytes, 0, bytes.Length);
                    fs.Close();
                    Response.ContentType = "application/octet-stream";//通知浏览器下载文件而不是打开
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(Fi.Name, System.Text.Encoding.UTF8));
                    Response.BinaryWrite(bytes);
                    Response.Flush();
                    Response.End();
                }
                else
                {
                    Response.Write("<script>alert('文件不存在!');</script>");
                }
            }
  • 相关阅读:
    在linux服务器上搭建nvidia-docker环境
    Mysql入门
    POSTMAN关联
    SQL之内连接与外连接
    JMeter线程组参数含义
    JMeter基本概念
    JMeter聚合报告参数含义
    JMeter录制脚本
    Mysql日期与时间类型及函数
    linux服务器上安装mysql
  • 原文地址:https://www.cnblogs.com/ccsbb/p/2007984.html
Copyright © 2011-2022 走看看