利用XMLHTTP下载文件,和以前的方法一样,先添加引用-COM-Microsoft Xml 3.0,然后在代码开始处写:
<xmp>using MSXML2;
</xmp>
下面就是主要的代码:
<xmp>private void Page_Load(object sender, System.EventArgs e)
{
string Url = &quot;http://dotnet.aspx.cc/Images/logoSite.gif&quot;;
string StringFileName = Url.Substring(Url.LastIndexOf(&quot;/&quot;) + 1);
string StringFilePath = Request.PhysicalApplicationPath;
if(!StringFilePath.EndsWith(&quot;/&quot;)) StringFilePath += &quot;/&quot;;
MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
_xmlhttp.open(&quot;GET&quot;,Url,false,null,null);
_xmlhttp.send(&quot;&quot;);
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 (&quot;文件已经得到。&lt;br&gt;&lt;a href=&#39;&quot; + Request.ApplicationPath + StringFileName +&quot;&#39; target=&#39;_blank&#39;&gt;&quot;);
Response.Write (&quot;查看&quot; + StringFileName + &quot;&lt;/a&gt;&quot;);
}
else
Response.Write (_xmlhttp.statusText);
Response.End();
}
</xmp>
分享到:
相关推荐
在.NET中利用XMLHTTP下载文件的代码
在.NET中利用XMLHTTP下载文件.txt 在ASP.NET中实现POST发送数据.txt 在IE浏览器中使用Windows窗体控件.txt 在SQL Server中保存和输出任意类型的文件.txt 怎么在Web.Config里写Sql Server连接字符串?.txt 正则表达式...
在ASP.Net中两种利用CSS实现多界面的方法 如何在客户端调用服务端代码 页面一postback,它就显示页面的最顶端,怎样让它定位在某一位置? 如何保证页面刷新后的滚动条位置 清除网页历史记录,屏蔽后退按钮! 如何传值...
第4章 实现了聊天室模块(利用ASP.net Ajax)。 第5章 ASP.net Ajax Control Toolkit控件应用。包括:利用AutoCompleteExtender控件实现自动完成的功能;利用NoBot控件自动拒绝垃圾发布程序;利用ReorderList控件...
Cell 插件用于开发B/S结构程序,使用Asp, Asp.net, Jsp, VbScript, JavaScript等语言开发,可以在浏览器中直接打印报表(非IE打印),带有国际化数字签名,让用户使用更方便,更安全。 • 具备Cell组件的所有特色...
Tomcat是一个免费的开源的Serlvet容器,在Tomcat中,应用程序的部署很简单,你只需将你的WAR放到Tomcat的webapp目录下,Tomcat会自动检测到这个文件,并将其解压。你在浏览器中访问这个应用的Jsp时,通常第一次会很...
在XML和DTD文件中,第一个定义的都是根元素。 3.Parent Element(父元素)/Child Element(子元素) 父元素是指包含有其它元素的元素,被包含的元素称为它的子元素。看上面的"结构树",其中是父元素,,是它的子元素,...
查看网页源代码 onclick="window.location = "view-source:"+ "http://www.csdn.net/""> 关闭输入法 自动全选 ()"> ENTER键可以让光标移到下一个输入框 (event.keyCode==13)event.keyCode=9"> 文本框的...