• 强制另存文件和加扩展名的代码c#


    强制另存为文件+扩展名的代码
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    namespace AspDotNet03
    {
    /// <summary>
    /// C11Down 负责 读取请求文件并 提示浏览器 另存为
    /// </summary>
    public class C11Down : IHttpHandler
    {
    public void ProcessRequest(HttpContext context)
    {
    //1.获取要下载的文件路径
    string strFilePath = context.Request.QueryString["n"];
    //2.转成物理路径
    strFilePath = context.Request.MapPath(strFilePath);

    //关键:添加一个相应报文头,强制浏览器 以另存为附件 的方式 打开 本次输出的响应报文
    context.Response.AddHeader("Content-Disposition", "attachment;filename=gzitcast.jpg");


    //3.将文件读取并输出给浏览器
    context.Response.WriteFile(strFilePath);
    }

    public bool IsReusable
    {
    get
    {
    return false;
    }
    }
    }
    }

  • 相关阅读:
    抚琴弹唱东流水
    借点阳光给你
    日月成双行影单
    一夜飘雪入冬来
    悼念钱学森
    我的青春谁作主
    重游望江楼有感
    雪后暖阳
    满城尽添黄金装
    敢叫岁月不冬天
  • 原文地址:https://www.cnblogs.com/kexb/p/3660391.html
Copyright © 2020-2023  润新知