<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title="js下载文件 无刷新下载文件示例代码(带c#)" id="card1">
<p> 游客</p><p>
标题:js下载文件 无刷新下载文件示例代码(带c#)<br/>
正文:<br/>
后台代码Handler.ashx <br/> 代码如下:<br/>&amp;lt;%@ WebHandler Language=&quot;C#&quot; Class=&quot;Handler&quot; %&amp;gt; <br/><br/>using System; <br/>using System.Web; <br/><br/>public class Handler : IHttpHandler { <br/><br/>public void ProcessRequest (HttpContext context) { <br/>string fileName = &quot;web.config&quot;;//客户端保存的文件名 <br/>string filePath = context.Server.MapPath(&quot;web.config&quot;);//路径 <br/>//以字符流的形式下载文件 <br/>System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open); <br/>byte[] bytes = new byte[(int)fs.Length]; <br/>fs.Read(bytes, 0, bytes.Length); <br/>fs.Close(); <br/>context.Response.ContentType = &quot;application/octet-stream&quot;; <br/>//通知浏览器下载文件而不是打开 <br/>context.Response.AddHeader(&quot;Content-Disposition&quot;, &quot;attachment; filename=&quot; + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); <br/>context.Response.BinaryWrite(bytes); <br/>context.Response.Flush(); <br/>context.Response.End(); <br/>} <br/><br/>public bool IsReusable { <br/>get { <br/>return false; <br/>} <br/>} <br/><br/>} <br/><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1233&amp;Page=1">[&lt;&lt;]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1233&amp;Page=1">[[1]]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1233&amp;Page=2">[2]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1233&amp;Page=3">[3]</a><a href="http://camnpr.com/wap.asp?mode=WAP&amp;act=View&amp;id=1233&amp;Page=3">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=1233">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=1233">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://camnpr.com/wap.asp">首页</a>
</p>
</card>
</wml>