Both WebClient and directory are powerful.

Source: Internet
Author: User

RX:

/* System. net. use of WebClient * system. net. webClient mywebclient = new system. net. webClient (); * synchronous download or asynchronous download ** synchronous download: * mywebclient. downloadfile (URL, Pagh); * after the download is complete, you can open system. diagnostics. process. start (Pagh); *** asynchronous download: * mywebclient. downloadfileasync (New uri (URL), Pagh); * you can set the event after download before download: * mywebclient. downloadfilecompleted + = new asynccompletedeventhandler (mywebclient_downloadfilecompleted ); * The event Delegate method is as follows: void mywebclient_downloadfilecompleted (Object sender, asynccompletedeventargs e) {MessageBox. show ("download completed, will be automatically opened soon"); system. diagnostics. process. start (XX); // throw new exception ("the method or operation is not implemented. ");} ** The downloading PATH variable Pagh can be set to a global variable * asynchronous downloading can perform other operations when multiple files are downloaded and large files are downloaded simultaneously, * set the download completion event. After the download is complete, the user will be notified. */

 

For the WebClient's Writing Method of winform upload and web server, see here: Portal

 

 

Directory is also very powerful

 

Introduction

// 1. obtain the current application path // The application is known before. startuppath (); // I didn't expect this to work with directory. getcurrentdirectory (); // 2. create if (directory. exists (! @ "D: \ Temp") {directory. createdirectory (@ "D: \ Temp");} // 3. create if (file. exists (! @ "D: \ temp \ temp.txt") {file. create (@ "D: \ temp \ temp.txt");} // the file can be replaced with the file below. createtext (@ "D: \ temp \ temp.txt"); // 3. delete // reload twice // a parameter indicates that only files in the target folder can be deleted. // The last parameter can be true or false. // if true, all files are deleted as false or only one Parameter only deletes all objects in the target folder and retains the subfolders directory. delete (@ "D: \ Temp"); // 4. move files or folders // move the temp folder on disk D to directory on disk E. move (@ "D: \ Temp", @ "E: \ Temp"); // obtain the Directory creation date and time directory. getcreationtime (directory. getcurrentdirectory (); // retrieves the parent directory of the specified path. getparent (directory. getcurrentdirectory (); // 5. obtain the list of files and folders in the current directory (including the names of files or folders) string [] ooxx1 = directory. getfilesystementries (directory. getcurrentdirectory (); // 6. obtain the directory list of files in the current directory (including the file name) string [] ooxx2 = directory. getfiles (directory. getcurrentdirectory (); // 7. obtain the Directory List (including the folder name) of the folder under the current directory string [] ooxx3 = directory. getdirectories (directory. getcurrentdirectory ()); // The first two parameters are reloaded. The second and third parameters are reloaded with three parameters. // The path to be queried for the first parameter. // The second parameter query character can be searched using regular expressions similar to that for computers. use *. PDF // The third parameter searchoption enumeration: // searchoption. alldirectories // search the current directory and all subdirectories // searchoption. topdirectoryonly searches for the current directory // classic msdn example: // process all files in the directory passed in, recurse on any directories/that are found, and process the files they contain. public static void processdirectory (string targetdirectory) {// process the list of files found in the directory. string [] fileentries = directory. getfiles (targetdirectory); foreach (string filename in fileentries) processfile (filename); // recurse into subdirectories of this directory. string [] subdirectoryentries = directory. getdirectories (targetdirectory); foreach (string subdirectory in subdirectoryentries) processdirectory (subdirectory);} // insert logic for processing found files here. public static void processfile (string path) {console. writeline ("processed file '{0 }'. ", PATH );}

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.