首页 > 编程 > .NET > 正文

.net中xmlhttp下载文件的方法参考

2024-07-10 12:58:38
字体:
来源:转载
供稿:网友
<%@ page language="c#"%>
<%@import namespace=msxml2%>
<script language="c#" runat="server">
private void page_load(object sender, system.eventargs e)
{
string url = "http://www.cccar.com.cn/images/index2_01.gif";
string stringfilename = url.substring(url.lastindexof("/") + 1);
string stringfilepath = request.physicalapplicationpath;
if(!stringfilepath.endswith("/")) stringfilepath += "/";
msxml2.xmlhttp _xmlhttp = new msxml2.xmlhttpclass();
_xmlhttp.open("get",url,false,null,null);
_xmlhttp.send("");
if( _xmlhttp.readystate == 4 )
{
if(system.io.file.exists(stringfilepath + stringfilename))
system.io.file.delete(stringfilepath + stringfilename);
system.io.filestream fs = new system.io.filestream(stringfilepath + stringfilename, system.io.filemode.createnew);
system.io.binarywriter w = new system.io.binarywriter(fs);
w.write((byte[])_xmlhttp.responsebody);
w.close();
fs.close();
response.write ("文件已经得到。<br><a href='" + request.applicationpath + "//" + stringfilename +"' target='_blank'>");
response.write ("查看" + stringfilename + "</a>");
}
else
//response.write (_xmlhttp.statustext);
response.end();
}
</script>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表