欢迎光临
我们一直在努力

利用XMLHTTP下载文件-ASP教程,XML相关

建站超值云服务器,限时71元/月

利用xmlhttp下载文件,和以前的方法一样,先添加引用-com-microsoft xml 3.0,然后在代码开始处写:

using msxml2;

下面就是主要的代码:

private void page_load(object sender, system.eventargs e)

{

string url = "http://dotnet.aspx.cc/images/logosite.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();

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 利用XMLHTTP下载文件-ASP教程,XML相关
分享到: 更多 (0)

相关推荐

  • 暂无文章