方法1:利用SQLServer
具体操作和实现过程:
1) 建立系统的启动文件,验证系统的更新标志,根据更新标志实现系统的更新。并读取配置文件中的业务主体模块,通过反射启动主体模块。一般为登陆窗口或系统的主窗口。
2) 建立独立的系统业务模块,包括系统的登陆和系统的主窗口等部分。
3) 建立系统的配置文件,记录系统的数据库配置和系统的启动模块。以及其他的配置信息。本文件可以自动更新。
4) 更新过程,通过数据库系统的二进制大对象操作,将所得对象,转化成文件后储存到本地硬盘。完成系统的更新。
5) 系统的发布时只包含一个独立的启动文件和一个配置文件。可以依靠邮件和复制完成系统的发布。
缺点:
1) 系统的独立启动文件不能自动更新,尽最大限度的减少启动文件的职责,最大限度地使用配置文件共享信息。
2) 系统和数据库系统紧密耦合,但系统建立在数据库的基础上,数据库必须有效。
方法2:利用代码
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.Net;
using System.Diagnostics;
namespace UpDate
{
public partial class Form1 : Form
{
private WebClient update = new WebClient();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string URL = @"https://files.cnblogs.com/mossan/Zhongwen.rar";
int n = URL.LastIndexOf('/');
string fileName = URL.Substring(n + 1, URL.Length - n - 1);
if (!(Directory.Exists(Application.StartupPath + "\\update")))
{
Directory.CreateDirectory(Application.StartupPath + "\\update");
}
try { update.DownloadFile(URL, Application.StartupPath + "\\update\\" + fileName); }
catch (WebException ex) { MessageBox.Show(ex.Message, "Error"); }
try
{
Process UnWinrar = new Process();
UnWinrar.StartInfo.FileName = "WinRAR.exe";
UnWinrar.StartInfo.Arguments = "e -o+ \"" + Application.StartupPath + "\\update\\" + fileName + "\"" + " \"" + Application.StartupPath + "\\update" + "\"";
UnWinrar.Start();
MessageBox.Show("解压缩完成!");
File.Copy(Application.StartupPath + "\\update\\" + "Zhongwen.exe", Application.StartupPath + "\\Zhongwen.exe", true);
Process ProZhongwen = new Process();
ProZhongwen.StartInfo.FileName = Application.StartupPath + "\\Zhongwen.exe";
ProZhongwen.Start();
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
this.Close();
}
}
}
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.Net;
using System.Diagnostics;
namespace UpDate
{
public partial class Form1 : Form
{
private WebClient update = new WebClient();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string URL = @"https://files.cnblogs.com/mossan/Zhongwen.rar";
int n = URL.LastIndexOf('/');
string fileName = URL.Substring(n + 1, URL.Length - n - 1);
if (!(Directory.Exists(Application.StartupPath + "\\update")))
{
Directory.CreateDirectory(Application.StartupPath + "\\update");
}
try { update.DownloadFile(URL, Application.StartupPath + "\\update\\" + fileName); }
catch (WebException ex) { MessageBox.Show(ex.Message, "Error"); }
try
{
Process UnWinrar = new Process();
UnWinrar.StartInfo.FileName = "WinRAR.exe";
UnWinrar.StartInfo.Arguments = "e -o+ \"" + Application.StartupPath + "\\update\\" + fileName + "\"" + " \"" + Application.StartupPath + "\\update" + "\"";
UnWinrar.Start();
MessageBox.Show("解压缩完成!");
File.Copy(Application.StartupPath + "\\update\\" + "Zhongwen.exe", Application.StartupPath + "\\Zhongwen.exe", true);
Process ProZhongwen = new Process();
ProZhongwen.StartInfo.FileName = Application.StartupPath + "\\Zhongwen.exe";
ProZhongwen.Start();
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
this.Close();
}
}
}