_XHTML/WEB_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

在.NET中利用XMLHTTP下载文件

作者:黑客防线网安XML教程基地 来源:黑客防线网安XML教程基地 浏览次数:0

本篇关键词:文件下载利用 
    利用XMLHTTP下载文件和以前的方法一样先添加引用-COM-Microsoft Xml 3.0,然后在代码开始处写:
  
  using MSXML2;
  下面就是主要的代码: 
   
   private void Page_Load(object sender, System.EventArgs e)
  {
   string Url = "http://dotnet.chinaitlab.com/UploadFiles_6597/200611/20061130113617553.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();

    希望这篇在.NET中利用XMLHTTP下载文件的文章能够对您有所帮助,如果您觉得这篇网站维护教程有用的话,别忘了推荐给您的朋友哦!如果您有好的经验方法,不妨拿出来和大家一起分享:假如每个人都拿出一个经验,那么我们都将额外的获取一堆他人的经验。
请记住本站永久域名:(黑客防线网安服务器维护方案维护基地)Www.Rongsen.Com.Cn
    黑客防线网安服务器维护方案本篇连接:http://kj.rongsen.com.cn/show-16219-1.html
网站维护教程更新时间:2012-04-06 01:14:27  【打印此页】  【关闭
0
顶一下
0
踩一下
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer