• 【转】Asp.net下载文件、文件流输出 直接输出文件


    一下所写的代码都是在下载页面page_load事件中:

    //直接输出文件形式

    Response.Clear(); Response.Buffer = true; Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Server.MapPath("~/Global.asax"),System.Text.Encoding.UTF8)); Response.WriteFile(Server.MapPath("~/Global.asax")); Response.Flush(); Response.Close();

     

    //输出文件流形式

    FileStream fileStream = new FileStream(Server.MapPath("~/Global.asax"), FileMode.Open);

    long fileSize = fileStream.Length; byte[] fileBuffer = new byte[fileSize]; fileStream.Read(fileBuffer, 0, (int)fileSize);

    //如果不写fileStream.Close()语句,用户在下载过程中选择取消,将不能再次下载 fileStream.Close(); Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Server.MapPath("~/Global.asax"), System.Text.Encoding.UTF8)); Response.AddHeader("Content-Length", fileSize.ToString()); Response.BinaryWrite(fileBuffer); Response.Flush(); Response.Close();

  • 相关阅读:
    Linux下文件的压缩和解压
    Env: Linux下Source Insight安装
    [uart]2.tty和uart的函数调用流程
    [uart]stty命令使用
    腾讯云的云数据库MYSQL配置
    MySQL分支Percona
    MYSQL的历史
    MYSQL的价格
    mysql之event
    Linux下设置网卡静态ip
  • 原文地址:https://www.cnblogs.com/yuan2013/p/3741639.html
Copyright © 2020-2023  润新知