Service side:
[WebMethod] Public stringGetnewservice (stringversion) { //Compare by version number if(Version = ="v1.0") { return "no new version! "; } Else { return @"E:\QMDownload\CashTest.exe";//returns an address with a new version in it! } }
View Code
Client:
//Automatic Update startJuran.CenterCash.WebService.UpdateService.WebService Server =NewWebService.UpdateService.WebService (); stringPath = Server. Getnewservice ("v1.x"); if(Path = ="no new version! ") { } Else { Try{WebClient wclient=NewWebClient (); Wclient.downloadfile (Path,"D:\\1.exe");//download server files to local, named 1.exeProcess Pro =NewProcess (); stringFileName =@"D:\\1.exe"; stringPara =""; ProcessStartInfo Myprocessstartinfo=NewProcessStartInfo (FileName, para); Pro. StartInfo=Myprocessstartinfo; Pro. Start (); while(!Pro. hasexited) {Pro. WaitForExit (); } intReturnValue =Pro. ExitCode; if(ReturnValue = =0) {MessageBox.Show ("the update is successful, please start the program! "); } } Catch(Exception ex) {MessageBox.Show (ex). ToString ()); } } //Automatic Update End
View Code
C#winform for Automatic Updates