Use XMLHTTP to download an object. Like the previous method, add reference-com-Microsoft XML 3.0 first, and thenCodeStart Point:
Using msxml2;
The following is the main code:
Private void page_load (Object sender, system. eventargs e) {string url = "http://dotnet.aspx.cc/Images/logoSite.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, SY Stem. io. filemode. createnew); system. io. binarywriter W = new system. io. binarywriter (FS); W. write (byte []) _ XMLHTTP. responsebody); W. close (); FS. close (); response. write ("the file has been obtained.
"); Response. Write (" View "+ stringfilename +" ");} else response. Write (_ XMLHTTP. statustext); response. End ();}
Article Referenced from: