添加引用 COM Microsoft Xml 3.0
protected
void
Page_Load(
object
sender, EventArgs e)
{
string url = " http://i.microsoft.com/h/all/i/ms_masthead_8x6a_ltr.jpg " ;
string fileName = url.Substring(url.LastIndexOf( " / " ) + 1 );
string filePath = Request.PhysicalApplicationPath;
if (filePath.EndsWith( " / " ))
{
filePath += " / " ;
}
XMLHTTP xmlhttp = new XMLHTTPClass();
xmlhttp.open( " get " , url, false , null , null );
xmlhttp.send( "" );
if (xmlhttp.readyState == 4 )
{
if (File.Exists(filePath + fileName))
{
File.Delete(filePath + fileName);
}
FileStream fs = new FileStream(filePath + fileName, FileMode.CreateNew);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(( byte [])xmlhttp.responseBody);
bw.Close();
fs.Close();
Response.Write( " 文件已经得到! " );
Response.Write( " <br><a href= " + Request.ApplicationPath + " / " + fileName + " > " + " 查看 " + fileName + " </a> " );
}
else
{
Response.Write(xmlhttp.statusText);
}
Response.End();
}
{
string url = " http://i.microsoft.com/h/all/i/ms_masthead_8x6a_ltr.jpg " ;
string fileName = url.Substring(url.LastIndexOf( " / " ) + 1 );
string filePath = Request.PhysicalApplicationPath;
if (filePath.EndsWith( " / " ))
{
filePath += " / " ;
}
XMLHTTP xmlhttp = new XMLHTTPClass();
xmlhttp.open( " get " , url, false , null , null );
xmlhttp.send( "" );
if (xmlhttp.readyState == 4 )
{
if (File.Exists(filePath + fileName))
{
File.Delete(filePath + fileName);
}
FileStream fs = new FileStream(filePath + fileName, FileMode.CreateNew);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(( byte [])xmlhttp.responseBody);
bw.Close();
fs.Close();
Response.Write( " 文件已经得到! " );
Response.Write( " <br><a href= " + Request.ApplicationPath + " / " + fileName + " > " + " 查看 " + fileName + " </a> " );
}
else
{
Response.Write(xmlhttp.statusText);
}
Response.End();
}