Code-Practical tips for using XMLHTTP to download files in. Net

Source: Internet
Author: User
Using XMLHTTP to download files, as in previous methods, add references-com-microsoft Xml 3.0, and then write at the beginning of the code:
Using MSXML2;
Here is the main code:
private void Page_Load (object sender, System.EventArgs e) {
String Url = "yun_qi_img/logoSite.gif";
String stringfilename = Url.substring (Url.lastindexof ("/") + 1);
string stringfilepath = Request.physicalapplicationpath;
if (! Stringfilepath.endswith ("/"))
Stringfilepath + "/";
MSXML2. XMLHTTP _xmlhttp = new MSXML2. Xmlhttpclass (); (" 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 (" documents have been obtained. <br><a href=& #39;" + Request.applicationpath + stringfilename +"& #39; target=& #39;_blank& #39;>");
Response.Write (" View " + stringfilename + "</a>");
Response.Write (_xmlhttp.statustext); Response.End ();}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.