IE直接下載匯總

來源:互聯網
上載者:User

 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中顯示常值內容

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.