English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Winform program automatic update is the first time I have done, I found the source code of automatic update on the Internet, and then tried for a long time according to some methods I saw online, but still made some mistakes. So I spent money to have someone else debug it successfully. Below is what I have fiddled with, for everyone's reference. If there are any mistakes, please correct them.
1、Since I publish automatic updates through the server's IIS, I need to manually copy the program to the directory under the IIS server before updating, make some changes, so that the client can update automatically. Therefore, the first step is not familiar with the IIS server (my system is Windows8):
Follow the above method, select and click OK. The system will automatically add these contents, then:
After the website is established, simply place the written files that need to be updated in the file directory corresponding to the selected physical path.
2、After the website is established, the next step is to figure out how to update it, that is, to update files from the server to the client. As for the specific process and central idea, I will not elaborate further, as there are many resources online.
3、The automatic source code download address cannot be found. If needed, please leave an email, and I will send it to you.
4、Generate the automatic source code class library, then reference the class library in your main program, and place the two files in the figure below and your main program in the same folder:
5、The call to the main program is placed before the login form in the main program. Since I cannot control whether the program needs to be updated, I need to establish a process, which is to create a table in the database including two fields
As shown in the figure above, the New field saves the latest version, while the Old field saves the previous version.
using Mulaolao.Forms; using Mulaolao.Procedure; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using Mulaolao.Other; using System.Threading; using StudentMgr; using System.Data; using System.Data.Sql; using System.Data.SqlClient; namespace Mulaolao {"}} static class Program {"}} //private static Mutex mutex; /// <summary> /// The main entry point of the application. /// </summary> [STAThread] static void Main( ) {"}} Application.EnableVisualStyles( ); Application.SetCompatibleTextRenderingDefault( false ); //Read the table DataTable da = SqlHelper.ExecuteDataTable( "SELECT * FROM R_UpdateforOrder" ); string news = "", old = ""; //If there is no data in the table, log in directly without updating if (da.Rows.Count < 1) {"}} //Set the login form to close after successful login and display the main form Login lg = new Login( ); lg.StartPosition = FormStartPosition.CenterScreen; lg.ShowDialog( ); if (lg.DialogResult == DialogResult.OK) {"}} Application.Run(new Form1( ) ); } else {"}} return; } } else {"}} //If the new version and the old version in the table are consistent, there is no need to update news = da.Rows[0]["New"].ToString( ); old = da.Rows[0]["Old"].ToString( ); if (news == old) {"}} //Set the login form to close after successful login and display the main form Login lg = new Login( ); lg.StartPosition = FormStartPosition.CenterScreen; lg.ShowDialog( ); if (lg.DialogResult == DialogResult.OK) {"}} Application.Run(new Form1( ) ); } else {"}} return; } } else {"}} //If the new version and old version in the table are inconsistent, it is necessary to update the old version to the new version and start the automatic update window SqlHelper.ExecuteNonQuery( "UPDATE R_UpdateforOrder SET Old=@Old", new SqlParameter( "@Old", news ) ); System.Diagnostics.Process.Start( Application.StartupPath + @"\AutoUpdate.exe" ); } } } } }
The next step is to go, after completion, the updated main program will start automatically.
6Talk about the main parameters in UpdateList.xml:
The following is the update version program I wrote (the New field in the table), placed on the client, in the version update folder in the third picture, run this program before updating the server, and update the latest database version:
The above content is the method I spent money on, not very advanced. There is no way, as I have not been in the industry for long and have no experience, I can't come up with an advanced one. Welcome to correct me in time. In fact, the main steps are: first set up the IIS server-->Create a new website-->Place the main program file, update file, and version update all in the same folder-->The main program calls the update program (mainly to judge when to perform automatic updates)-->Configure the parameters in the automatic update file-->The version comparison table in the database is set up-->Before updating, cover the program on the server, modify the content of the automatic update xml file, and run the version update-->Waiting for the client to update itself
Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (When reporting, please replace # with @) for reporting, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.