您好,欢迎访问一九零五行业门户网

JS下载文件|无刷新下载文件示例代码_javascript技巧

后台代码handler.ashx
复制代码 代码如下:
using system;
using system.web;
public class handler : ihttphandler {
public void processrequest (httpcontext context) {
string filename = web.config;//客户端保存的文件名
string filepath = context.server.mappath(web.config);//路径
//以字符流的形式下载文件
system.io.filestream fs = new system.io.filestream(filepath, system.io.filemode.open);
byte[] bytes = new byte[(int)fs.length];
fs.read(bytes, 0, bytes.length);
fs.close();
context.response.contenttype = application/octet-stream;
//通知浏览器下载文件而不是打开
context.response.addheader(content-disposition, attachment; filename= + httputility.urlencode(filename, system.text.encoding.utf8));
context.response.binarywrite(bytes);
context.response.flush();
context.response.end();
}
public bool isreusable {
get {
return false;
}
}
}
前端代码:
复制代码 代码如下:
aaaaa
bbbbb
ccccc
其它类似信息

推荐信息