教程集 www.jiaochengji.com
教程集 >  脚本编程  >  Asp.net  >  正文 .net中xmlhttp下载文件的方法参考

.net中xmlhttp下载文件的方法参考

发布时间:2018-10-06   编辑:jiaochengji.com
教程集为您提供.net中xmlhttp下载文件的方法参考等资源,欢迎您收藏本站,我们将为您提供最新的.net中xmlhttp下载文件的方法参考资源
<%@ Page language="c#"%>
<%@import namespace=MSXML2%>
<script language="c#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
string Url = "http://www.cccar.com.cn/images/index2_01.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();
}
</script>

您可能感兴趣的文章:
.net中xmlhttp下载文件的方法参考
js之ActiveX控件使用说明 new ActiveXObject()
php 获取网页内容的四种方法
javascript 判断浏览器版本的代码
[原创]ajax 实现用户注册功能教程二
利用js(jquery)操作Cookie的方法说明
xmlhttp:open方法POST、GET参数的区别分析
php ajax实现数据调用
Windows 2003下安装VS2008时.NetFramework3.5组件安装失败的解决方法
php+ajax动态验证用户名是否已注册的代码

[关闭]
~ ~