zoukankan      html  css  js  c++  java
  • 文件下载功能

    代码如下:

    /// <summary>
    /// 附件下载
    /// </summary>
    /// <param name="attachId">附件ID</param>
    public void DownloadAttach(int attachId)
    {
        Edu_Attach edu_Attach = edu_AttachService.findById<Edu_Attach>(attachId);
        if (edu_Attach != null)
        {
            HttpContext context = (HttpContext)ctx.web.Context;
            if (context != null)
            {
                string filePathName = PathHelper.Map(sys.Path.DiskPhoto) + edu_Attach.AttachContent.Replace("/static/upload/image", "").Replace("/", "\");
                int pos = filePathName.LastIndexOf("\");
                string fileName = filePathName.Substring(pos + 1);
                string UserAgent = context.Request.ServerVariables["http_user_agent"].ToLower();
                if (UserAgent.IndexOf("firefox") == -1)
                {
                    //非火狐浏览器
                    context.Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(edu_Attach.AttachName));
                }
                else
                {
                    context.Response.AddHeader("content-disposition", "attachment;filename=" + edu_Attach.AttachName);
                }
                FileStream fs = new FileStream(filePathName, FileMode.Open, FileAccess.Read);
                byte[] bArr = new byte[fs.Length];
                fs.Read(bArr, 0, bArr.Length);
                fs.Close();
                context.Response.ContentEncoding = Encoding.UTF8;
                context.Response.BinaryWrite(bArr);
                context.Response.Flush();
                context.Response.End();
            }
        }
    }
    View Code
  • 相关阅读:
    修改计算机名并更新sqlserver中存储的服务器名称
    SqlServer递归查询
    CSS实现文本溢出显示省略号
    浏览器缓存
    闭包(匿名函数) php
    github添加ssh认证
    hive内置方法一览
    Redis went away
    慢查询日志分析(mysql)
    慢查询日志(mysql)
  • 原文地址:https://www.cnblogs.com/s0611163/p/3601938.html
Copyright © 2011-2022 走看看