zoukankan      html  css  js  c++  java
  • IE直接下载汇总

     JS效果:

    --------------------------------------------------------------------------------
    <a href="#" onclick="openfile()">下载</a>
    <script language="JavaScript">
     function openfile()
      {
       var a =window.open("aaa.txt","_blank","");
       a.document.execCommand("SaveAs");
       a.close();
      }
    </script>

    --------------------------------------------------------------------------------
    <script language="C#">
    <!--
        /**//// <summary>
        /// 用于文件的下载
        /// </summary>
        /// <param name="id">要下载的文件编号</param>
        private void DownLoadDocument(string id)
         {
           //命名空间 缩写,
            ****.BLL.Document bll = new XTMYDocMgmt.BLL.Document();
            ****.Model.Document model = bll.GetModel(Convert.ToInt32(id));

            string rootPath  = @Server.MapPath("~") + model.DocPath;
            FileInfo toDownload = new FileInfo(rootPath);

            //文件扩展名
            string strExt = Path.GetExtension(rootPath);

            Response.Clear();
            //Response.ContentType = "application/x-zip-compressed";
            Response.Charset = "utf-8";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            //文件保存时的名字。。处理中文乱码和名字中有空格的问题
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(model.DocName).Replace("+","%20") + strExt);

            //Response.WriteFile(rootPath);
            Response.TransmitFile(rootPath);

            Response.End();
        }

    //-->
    </script>

     --------------------------------------------------------------------------------

    <script language="c#">
    <!--
    //用流的方法
    Response.AddHeader("Content-Disposition",   "attachment;   filename=aaa.txt"   );  
    Response.ContentType   =   "application/octet-stream";  
    Response.Flush();  
    Response.Close();
     
    //-->
    </script>


    --------------------------------------------------------------------------------
    <script language="c#">
    <!--

    //方法二

    Response.AddHeader("Content-Disposition",   "attachment;   filename=aaa.txt"   );  
    System.IO.StreamReader   sr   =   new   StreamReader(@"c:\aaa.txt",System.Text.Encoding.Default);  
    Response.Write(sr.ReadToEnd());  
    sr.Close();  
    Response.Flush();  
    Response.Close();

    //-->
    </script>


     
    --------------------------------------------------------------------------------

    其他还可以通过IIS设置注册一下
     


    我在win2003+iis6中建了个web在显示txt文件时:直接出现下载的页面。。。而不能显示内容。。。  
      我已经在MIME中加入.txt   txt/plain   ,我现在想直接在web中显示文本内容

  • 相关阅读:
    自定义事件的触发dispatchEvent
    [转]ProxmoxVE 干掉 VMware
    【转】怎么去阅读Chromium的源码?
    Delphi内存专题
    Delphi 线程同步技术(转)
    【纸模】六角大王 Super 5.6 CHS 简体中文版 U20080725+[手册]窗口与工具的概要(PDF格式)
    ReSharper反编译C#类库
    CS DevExpress程序启动(主窗体初始化优化)
    【EasyNetQ】- 发布/订阅模式
    Intellij Idea调试java文件时 怎么跳过class文件?
  • 原文地址:https://www.cnblogs.com/winner/p/837295.html
Copyright © 2011-2022 走看看