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>");
                }
            }
  • 相关阅读:
    布局(layout)文件图形界面不能显示:An error has occurred. See error log for more details. java.lang.NullPointe
    Mac下无法推出硬盘
    Excel导入导出数据库(MVC)
    json导入数据库
    XML导入数据库
    Excel表格导入数据库
    Lambda高级查询
    Linq高级查询
    多线程
    反射
  • 原文地址:https://www.cnblogs.com/ccsbb/p/2007984.html
Copyright © 2011-2022 走看看