. Net implements batch file download

Source: Internet
Author: User

. Net implements batch file download

The program implementation principle is relatively simple, mainly using the c # webclient class and filestream class. The c # webclient class is in the system.net namespace.

The main function is to send data to the resource identified by the uri and receive data from the resource identified by the uri. We use the downloadfile () method

Download the file to your local device. Then, use the instance object of the filestream class to write the file data to the local file as a data stream. This completes the download of network files.


Tian

Add using system.net;
      
String https tutorial tr is the download url;
String saveurl;

Private bool getandsavefile (string httpstr, string saveurl)
        {

Try
            {
              
If (saveurl. lastindexof ("")! = Saveurl. length)
                {
Saveurl = saveurl + "";
                }


Webclient mywebclient = new webclient ();
Int I = httpstr. lastindexof ("/");
String filename = httpstr. substring (I + 1, httpstr. length-I-1 );

Mywebclient. downloadfile (httpstr, saveurl + filename );

Return true;
            }
Catch (exception ex)
            {
// This. errorlist. add (ex. message );
Return false;
            }

        }


Implementation principle:

 

Related Article

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: info-contact@alibabacloud.com 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.