zoukankan      html  css  js  c++  java
  • FileStream下载文件(物理路径)

    //以字符流的形式下载文件
                            FileStream fs = new FileStream(filePath, FileMode.Open); 
                            byte[] bytes = new byte[(int)fs.Length];
                            fs.Read(bytes, 0, bytes.Length);
                            fs.Close();
                            Response.Charset = "utf-8";
                            Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
                            Response.ContentType = "application/octet-stream";
                            if (HttpContext.Current.Request.UserAgent.ToUpper().Contains("MSIE") || 
                                HttpContext.Current.Request.UserAgent.ToUpper().Contains("TRIDENT")||
                                HttpContext.Current.Request.UserAgent.ToUpper().Contains("EDGE"))
                            {
                                fileName = HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);
                            }
                            else
                            {
                                fileName = fileName.Replace(" ", "_");
                            }
                            //fileName = HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);
                            Response.AddHeader("Content-Disposition", "attachment;   filename=" + fileName);
                            Response.BinaryWrite(bytes);
                            Response.Flush();
                            Response.End();
    View Code

    filePath路径

     public string GetDownPath(string RecordNum, string Name)
            {
                string sPath = Page.Server.MapPath("/");
                string filePath = Path.Combine(Path.Combine(sPath, "Upload\Attachment\" + RecordNum), Name);
                return filePath;
            }
    View Code
    收藏
    关注
    评论
  • 相关阅读:
    无缝滚动轮播图
    angular 1.6指令与服务
    angular 1.6路由
    javascript 对象
    JavaScript的运算符
    初识JavaScript!
    git常用命令(二)文字版
    CSS水平垂直居中
    收藏的一些牛逼博客
    html5 学习汇总
  • 原文地址:https://www.cnblogs.com/yidengbone/p/7463237.html
Copyright © 2011-2022 走看看