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>");
                }
            }
  • 相关阅读:
    Codesys——限定符的使用方法[来自Codesys的Help]
    分页后台
    多条件查询判断
    添加跟反射
    试图页面分页首选
    动态游标存储过程 表名为参数
    索引器
    泛型 Generics
    Win10 锁屏图片 路径
    SQL2014 error 40 ( Microsoft SQL Server, 错误2)
  • 原文地址:https://www.cnblogs.com/ccsbb/p/2007984.html
Copyright © 2011-2022 走看看