国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

在.NET中利用XMLHTTP下載文件的代碼

2020-01-18 01:44:38
字體:
來源:轉載
供稿:網友
利用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();}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 龙州县| 金山区| 萍乡市| 顺义区| 永清县| 德江县| 远安县| 阿拉善左旗| 申扎县| 上虞市| 延吉市| 永和县| 湄潭县| 池州市| 余干县| 许昌县| 洛宁县| 安泽县| 金堂县| 抚州市| 武威市| 永兴县| 调兵山市| 台安县| 苍梧县| 沙洋县| 赤水市| 南皮县| 北安市| 龙泉市| 株洲市| 淮北市| 连城县| 淅川县| 遂川县| 宽城| 宿松县| 洪泽县| 肥城市| 自治县| 邮箱|