. 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: