zoukankan      html  css  js  c++  java
  • 利用Response的WriteFile方法输出一些文件

            string path = Server.MapPath("~/字符串专题.doc");//文件的路径

            System.IO.FileInfo file = new System.IO.FileInfo(path);

            Response.Clear();

            Response.Charset = "utf-8";//设置输出的编码

            Response.ContentEncoding = System.Text.Encoding.UTF8;

            // 添加头信息,为"文件下载/另存为"对话框指定默认文件名   

            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));

            // 添加头信息,指定文件大小,让浏览器能够显示下载进度   

            Response.AddHeader("Content-Length", file.Length.ToString());

            // 指定返回的是一个不能被客户端读取的流,必须被下载   

            Response.ContentType = "application/msword";

            // 把文件流发送到客户端   

            Response.WriteFile(file.FullName);

            Response.End();

    重要说明:当您在 ASP.NET 应用程序的 Web.config 文件中将编译元素的 debug 属性值设置为 false 时,必须针对要下载的文件大小将 server.scripttimeout 属性设置为适当的值。默认情况下,server.scripttimeout 值被设置为 90 秒。但是,当 debug 属性被设置为 true 时,server.scripttimeout 值将被设置为一个非常大的值(30,000,000 秒)。

  • 相关阅读:
    jQuery Asynchronous
    Best Pratices——Make the Web Faster
    Asynchronous
    Deferred
    w3 protocol
    Android 设置wifi共享电脑服务器资源
    VC++ 6.0创建MFC工程时的初级备要点(二)
    【LeetCode】Pascal's Triangle II (杨辉三角)
    POJ 1564 Sum It Up(DFS)
    CSS写表格
  • 原文地址:https://www.cnblogs.com/zorro8z8/p/2729775.html
Copyright © 2011-2022 走看看