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

首頁 > 編程 > .NET > 正文

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

2024-07-10 12:40:23
字體:
來源:轉載
供稿:網(wǎng)友
利用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 ("文件已經(jīng)得到。<br><a href='" + Request.ApplicationPath + StringFileName +"' target='_blank'>");     
Response.Write ("查看" + StringFileName + "</a>"); 

else 
Response.Write (_xmlhttp.statusText);    Response.End();}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 临沧市| 林甸县| 张家界市| 平乡县| 江都市| 郎溪县| 金堂县| 福州市| 湘潭县| 页游| 桂阳县| 江城| 陇川县| 子洲县| 安泽县| 东台市| 涟水县| 新宁县| 新闻| 英山县| 龙胜| 竹山县| 南投市| 文登市| 德令哈市| 县级市| 桦川县| 广元市| 杭州市| 赞皇县| 泾源县| 马山县| 盱眙县| 南陵县| 桐乡市| 仁怀市| 贵定县| 新竹县| 枣强县| 凤城市| 芷江|