zoukankan      html  css  js  c++  java
  • c#下载文件案例

    public static void HttpDown(string fileName, System.Web.UI.Page p_Page,string floder)
    {
    string path = fileName;
    //输出到客户端
    FileInfo file = new FileInfo(path);
    p_Page.Response.Clear();
    p_Page.Response.Charset = "GB2312";
    p_Page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
    //添加头信息,为"文件下载/另存为"对话框指定默认文件名
    p_Page.Response.AddHeader("Content-Disposition", "attachment; filename=" + p_Page.Server.UrlEncode(file.Name));
    //添加头信息,指定文件大小,让浏览器能够显示下载进度
    p_Page.Response.AddHeader("Content-Length", file.Length.ToString());
    //指定返回的是一个不能被客户端读取的流,必须被下载
    p_Page.Response.ContentType = "application/ms-excel";
    //把文件流发送到客户端
    p_Page.Response.WriteFile(file.FullName);
    p_Page.Response.Flush();
    Directory.Delete(floder, true);
    }

  • 相关阅读:
    文章参考
    选择标识符(identifier)
    linux常见命令2
    Django框架之MVT(1)
    Tornado入门二
    2.Flask-jinjia2模板
    JQuery扩展和事件
    JQuery文档操作
    Jquery学习
    Jquery属性操作(入门二)
  • 原文地址:https://www.cnblogs.com/guozefeng/p/3584108.html
Copyright © 2011-2022 走看看