利用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();
}查看 http://www.qqread.com/xml-soap/e238381.html
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- .NET移动与嵌入式技术 (5882篇文章)
- .NET开发手册 (5587篇文章)
- Ajax技术核心 (176篇文章)
- XHTML 代码规范 (530次浏览)
- XML之CSS和XSL精解(1) (314次浏览)
- 利用Digester把XML转换成为Java对象 (143次浏览)
- XML SOAP应用简介 (131次浏览)
- W3C XML Schema 与文档类型定义 (116次浏览)
- XML、DataSet、DataGrid结合写成广告管理程 (109次浏览)
- dotText源码阅读(4)--DTO和数据访问 (108次浏览)
- Publishing Pages with PUT (65次浏览)
- 如何用MSXML2操作XML配置文件 (14次浏览)



