因为网上找了很多都不能直接用,所有写了这么详细一个教程,希望帮助大家!如果遇到问题欢迎回复询问,我也是个业余搞C#的,有错误也欢迎大家指出!对C#不是很熟,擅长C语音,网上找的不能自己用,就按照自己需求改的,因为程序不大,所有就直接控制升级,不需要点击任何按钮。大致流程:主程序开机后初始化里面加载升级程序,升级程序读取本地的XML和从服务器下载的XML看是否需要升级,如果升级就下载高版本升级程序,然后关闭当前低版本程序,再打开高版本升级的程序,接在删除第版本程序文件,最好下载服务器的XML文档覆盖本地是的!升级程序已经写好备注,有点语法基础应该都可以成功!使用时需要吧升级程序的EXE和主程序EXE还有XML放在一个文件夹里面,XML文件需要修改你服务器存放的升级文件路径及程序名。自己的主程序初始化里面添加这么一段: string str = System.Environment.CurrentDirectory + "\\" + "Check_SoftwareV1.1.exe";//获得当前运行程序的路径
            try
            {
                Process.Start(str);//打开升级程序
            }
            catch 
            {
                MessageBox.Show("检查程序运行出错,请注意文件是否存在.", "错误");//错误处理
            }升级程序主要代码如下:
这个工程可以去资料下载:http://download.csdn.net/download/th199301/10198681
private void FrmUpdate_Load(object sender, System.EventArgs e)
{
string localXmlFile = Application.StartupPath + "\\UpdateList.xml";//本地XML路径
string serverXmlFile = string.Empty;
try//从本地读取更新配置文件信息
{
                LocalXmlFiles = new XmlFiles(localXmlFile);
}
catch
{
MessageBox.Show("读取本地配置文件出错!","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.Close();
return;
}
//获取服务器地址
            updateUrl = LocalXmlFiles.GetNodeValue("//Url");//通过本地XML获得服务器地址 AppUpdater appUpdater = new AppUpdater();
            appUpdater.UpdaterUrl = updateUrl + "/UpdateList.xml";//服务器XML路径
            serverXmlFile = appUpdater.UpdaterUrl;
            try//从服务器读取更新配置文件信息
            {               
                ServerXmlFiles = new XmlFiles(serverXmlFile);
            }
            catch
            {
                MessageBox.Show("读取服务器配置文件出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
                return;
            } //与服务器连接,下载更新配置文件
try
{
                tempUpdatePath = Environment.GetEnvironmentVariable("Temp") + "\\" + "_" + LocalXmlFiles.FindNode("//Application").Attributes["applicationId"].Value + "_" + "y" + "_" + "x" + "_" + "m" + "_" + "\\";
appUpdater.DownAutoUpdateFile(tempUpdatePath);//下载服务器XML到本地临时地址
}
catch
{
MessageBox.Show("与服务器连接失败,操作超时!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.Close();
return; } //获取更新文件列表
Hashtable htUpdateFile = new Hashtable(); serverXmlFile = tempUpdatePath + "UpdateList.xml";//本地保存的服务器XML路径
if(!File.Exists(serverXmlFile))
{
return;
} availableUpdate = appUpdater.CheckForUpdate(serverXmlFile,localXmlFile,out htUpdateFile);//判断是否有更新
if (availableUpdate > 0)//有更新
{
                string str = System.Environment.CurrentDirectory + "\\";//获得当前运行程序的路径
                Updat1AppExe = ServerXmlFiles.GetNodeValue("//EntryPoint");//获得要升级的程序名
                appUpdater.UpdaterUrl = updateUrl + "/" + Updat1AppExe;//获得升级程序下载地址
                Download(appUpdater.UpdaterUrl, str);//下载升级程序
                mainAppExe = LocalXmlFiles.GetNodeValue("//EntryPoint");//从本地XML获得程序名
                Process[] allProcess = Process.GetProcesses();//获得所有进程
                foreach (Process p in allProcess)
                {
                    if (p.ProcessName.ToLower() + ".exe" == mainAppExe.ToLower())//查找当前程序的进程
                    {
                        for (int i = 0; i < p.Threads.Count; i++)
                            p.Threads[i].Dispose();
                        p.Kill();//关闭当前程序进程                       
                        Process.Start(Updat1AppExe);//打开升级程序
                        str = System.Environment.CurrentDirectory +"\\"+ mainAppExe;//获得当前运行程序的路径
                        File.Delete(@str);//删除原程序
                        appUpdater.UpdaterUrl = updateUrl + "/UpdateList.xml";//获得服务器XML下载地址
                        str = System.Environment.CurrentDirectory;
                        Download(appUpdater.UpdaterUrl, str);//下载XML直接覆盖                     
                        break;
                    }
                }
}
            this.Close();//关闭升级程序
}         /// 下载服务器文件并保存到客户端
        /// </summary>
        /// <param name="uri">被下载的文件地址,如:文件路径、url地址、ftp地址(包含文件名)</param>
        /// <param name="savePath">存放的目录(不包含文件名)</param>
        public static bool Download(string uri, string savePath)
        {
            //从文件路径中获取文件名
            string fileName;
            if (uri.IndexOf("\\") > -1)
            {
                fileName = uri.Substring(uri.LastIndexOf("\\") + 1);
            }
            else
            {
                fileName = uri.Substring(uri.LastIndexOf("/") + 1);
            }            //设置文件保存路径:路径+"\"+文件名.后缀、路径+"/"+文件名.后缀
            if (!savePath.EndsWith("/") && !savePath.EndsWith("\\"))
            {
                savePath = savePath + "/"; //也可以是savePath + "\\"
            }            savePath += fileName;   //另存为的绝对路径+文件名            //下载文件
            WebClient client = new WebClient();
            try
            {
                client.DownloadFile(uri, savePath);
            }
            catch (Exception ex)
            {
 //               Logger.Error(typeof(DownloadFile), "下载文件失败", ex);
                return false;
            }            return true;
        }