Use XMLHTTP to download an object. Like the previous method, add reference-COM-Microsoft Xml 3.0 first, and then write at the beginning of the Code:
Using MSXML2;
The following is the main code:
Private void Page_Load (object sender, System. EventArgs e ){
String Url = & quot; http://dotnet.aspx.cc/Images/logoSite.gif" ;;
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 ;);
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; the file has been obtained. & Lt; br & gt; & lt; a href = & #39; & quot; + Request. applicationPath + StringFileName + & quot; & #39; target = & #39; _ blank & #39; & gt; & quot ;);
Response. Write (& quot; view & quot; + StringFileName + & quot; & lt;/a & gt; & quot ;);
}
Else
Response. Write (_ xmlhttp. statusText); Response. End ();}