利用XMLHTTP下载文件
和以前的方法一样
先添加引用-COM-Microsoft Xml
然后在代码开始处写
using MSXML;
下面就是主要的代码
private void Page_Load(object sender SystemEventArgs e)
{
string Url = _//gif;
string StringFileName = UrlSubstring(UrlLastIndexOf(/) + );
string StringFilePath = RequestPhysicalApplicationPath;
if(!StringFilePathEndsWith(/)) StringFilePath += /;
MSXMLXMLHTTP _xml();
_xmlhttpopen(GETUrlfalsenullnull);
_xmlhttpsend();
if( _xmlhttpreadyState == )
{
if(SystemIOFileExists(StringFilePath + StringFileName))
SystemIOFileDelete(StringFilePath + StringFileName);
SystemIOFileStream fs = new SystemIOFileStream(StringFilePath + StringFileName SystemIOFileModeCreateNew);
SystemIOBinaryWriter w = new SystemIOBinaryWriter(fs);
wWrite((byte[])_xmlhttpresponseBody);
wClose();
fsClose();
ResponseWrite (文件已经得到<br><a + RequestApplicationPath + StringFileName + target=_blank>);
ResponseWrite (查看 + StringFileName + </a>);
}
else
ResponseWrite (_xmlhttpstatusText);
ResponseEnd();
}