C#实现程序的版本自动升级更新

我们做了程序,不免会有版本升级,这就需要程序有自动版本升级的功能。

 

 

把代码编译为一个类库文件,通过程序引用就OK啦。

传入的参数已经有注释了。

下面是更新的XML文件类容,传到空间上面就可以了,得到XML文件的地址。

 
 
1 <? xml version="1.0" encoding="utf-8" ?>
2
< Update >
3
< Soft Name ="BlogWriter" >
4
< Verson > 1.0.1.2 </ Verson >
5
< DownLoad > http://www.csdn.net/BlogWrite.rar </ DownLoad >
6
</ Soft >
7
</ Update >

程序更新调用方法:

 1、先引用上面的DLL。

 2、调用方法代码 如下:

 
 
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using System.IO;
9 using System.Threading;
10 using System.Net;
11 using System.Xml;
12 using Update;
13
14 namespace UpdateTest
15 {
16 public partial class Form1 : Form
17 {
18 public Form1()
19 {
20 InitializeComponent();
21 checkUpdate();
22 }
23
24 public void checkUpdate()
25 {
26 SoftUpdate app = new SoftUpdate(Application.ExecutablePath, " BlogWriter " );
27 app.UpdateFinish += new UpdateState(app_UpdateFinish);
28 try
29 {
30 if (app.IsUpdate && MessageBox.Show( " 检查到新版本,是否更新? " , " Update " , MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
31 {
32
33 Thread update = new Thread( new ThreadStart(app.Update));
34 update.Start();
35 }
36 }
37 catch (Exception ex)
38 {
39 MessageBox.Show(ex.Message);
40 }
41 }
42
43 void app_UpdateFinish() {
44 MessageBox.Show( " 更新完成,请重新启动程序! " , " Update " , MessageBoxButtons.OK, MessageBoxIcon.Information);
45 }
46
47 }
48 }
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值