把代碼編譯為一個類庫文件,通過程序引用就OK啦。
傳入的參數(shù)已經(jīng)有注釋了。
下面是更新的XML文件類容,傳到空間上面就可以了,得到XML文件的地址。
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8" ?>
<Update>
<Soft Name="BlogWriter">
<Verson>1.0.1.2</Verson>
<DownLoad>http://www.jb51.net/BlogWrite.rar</DownLoad>
</Soft>
</Update>
程序更新調(diào)用方法:
1、先引用上面的DLL。
2、調(diào)用方法代碼 如下:
復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Net;
using System.Xml;
using Update;
namespace UpdateTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
checkUpdate();
}
public void checkUpdate()
{
SoftUpdate app = new SoftUpdate(Application.ExecutablePath, "BlogWriter");
app.UpdateFinish += new UpdateState(app_UpdateFinish);
try
{
if (app.IsUpdate && MessageBox.Show("檢查到新版本,是否更新?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Thread update = new Thread(new ThreadStart(app.Update));
update.Start();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void app_UpdateFinish() {
MessageBox.Show("更新完成,請重新啟動程序!", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}