Download and install the Server installation package from Winform.

Source: Internet
Author: User

Download and install the Server installation package from Winform.

The Code contains the code for detecting the local installation drive letter.

1. Define the download delegate event (used to implement the frontend progress bar update and callback after the download is complete): 2 private delegate void Action (); 3 private string diverUrl = ConfigurationManager. deleetask[ "diverUrl"]; // http: Form 4 // page initial loading event 5 private void frmProgressBar_Load (object sender, EventArgs e) 6 {7 // get the storage path 8 GetRemovableDeviceId (); 9 if (File. exists (_ drivesName) 10 {11 // If the installation package Exists, install 12 var process = Process directly. start (_ drivesName); 13 if (process! = Null) process. waitForExit (); 14 // Process15 this. close (); 16} 17 else18 {19 // The installation package does not exist -- Download 20 DownloadFile (diverUrl, _ drivesName, DownloadProgressChanged, downloadFileCompleted ); 21} 22} 23 24 // download 25 private void downloadFileCompleted () 26 {27 Process. start (_ drivesName); 28 this. close (); 29} 30 31 // detects the 32 public void GetRemovableDeviceId () 33 {34 List <string> drivesList = new List <string> (); 35 Drive Info [] dr = DriveInfo. getDrives (); 36 foreach (DriveInfo dd in dr) 37 {38 if (dd. driveType = DriveType. CDRom | dd. driveType = DriveType. removable) // filter out the drive disk or mobile USB flash drive 39 {40 break; 41} 42 else43 {44 drivesList. add (dd. name); 45} 46} 47 // drive disk evicted 48 for (int I = 0; I <drivesList. count; I ++) 49 {50 // other drive letters 51 if (drivesList [I]. indexOf ("C") =-1) 52 {53 _ drivesName = drivesList [drivesList. count-1]. replace (": \ "," ") +": Cam_Ocx.exe "; 54 return; 55} 56 else57 {58 _ drivesName = drivesList [I]. replace (":\\", "") + ": Cam_Ocx.exe"; 59} 60} 61} 62 // download the 63 private void DownloadFile (string url, string savefile, action <int> downloadProgressChanged, Action downloadFileCompleted) 64 {65 WebClient client = new WebClient (); 66 if (downloadProgressChanged! = Null) 67 {68 client. downloadProgressChanged + = delegate (object sender, DownloadProgressChangedEventArgs e) 69 {70 this. invoke (downloadProgressChanged, e. progressPercentage); 71}; 72} 73 if (downloadFileCompleted! = Null) 74 {75 client. downloadFileCompleted + = delegate (object sender, AsyncCompletedEventArgs e) 76 {77 this. invoke (downloadFileCompleted); 78}; 79} 80 client. downloadFileAsync (new Uri (url), savefile); 81} 82 // display progress bar 83 private void DownloadProgressChanged (int val) 84 {85 progressBar1.Value = val; 86 lbValue. text = val + "%"; 87}View Code

 

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.