先添加引用-COM-Microsoft Xml 3.0:

using MSXML2;

下面就是主要的代码:

private void Page_Load(object sender, System.EventArgs e) { string Url = "<font face="Verdana"><a href="http://www.baidu.com/img/logo-yy.gif" target="_blank" rel="nofollow">http://www.baidu.com/img/logo-yy.gif</a></font>";<br> string StringFileName = Url.Substring(Url.LastIndexOf("/") + 1);<br> string StringFilePath = Request.PhysicalApplicationPath;<br> if(!StringFilePath.EndsWith("/")) StringFilePath += "/";<br> MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();<br> _xmlhttp.open("GET",Url,false,null,null);<br> _xmlhttp.send("");<br> if( _xmlhttp.readyState == 4 )<br> {<br> if(System.IO.File.Exists(StringFilePath + StringFileName)) <br> System.IO.File.Delete(StringFilePath + StringFileName);<br> System.IO.FileStream fs = new System.IO.FileStream(StringFilePath + StringFileName, System.IO.FileMode.CreateNew);<br> System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);<br> w.Write((byte[])_xmlhttp.responseBody);<br> w.Close();<br> fs.Close();<br> Response.Write ("文件已经得到。<br><a href="/default/index/url?u=aHR0cHM6Ly93d3cuY25ibG9ncy5jb20iICsgUmVxdWVzdC5BcHBsaWNhdGlvblBhdGggKyBTdHJpbmdGaWxlTmFtZSArIg==" href_cetemp='" + Request.ApplicationPath + StringFileName +"' target="_blank" rel="nofollow">");<br> Response.Write ("查看" + StringFileName + "</a>");<br> }<br> else<br> Response.Write (_xmlhttp.statusText);<br> Response.End();<br> }<br>

相关文章: