基本信息
源码名称:C# 版本在线升级(更新)示例源码
源码大小:0.26M
文件格式:.rar
开发语言:C#
更新时间:2018-06-11
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 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.Xml;
using System.IO;
using System.Diagnostics;

namespace AutoUpdateServer
{
    public partial class MainForm : Form
    {
        XmlDocument xmlDoc = new XmlDocument();
        XmlElement oElmntRoot;

        #region Method

        public MainForm()
        {
            InitializeComponent();
        }

        private bool createRootNode()
        {
            try
            {
                oElmntRoot = xmlDoc.CreateElement("update");
                //Second Child: update 
                xmlDoc.AppendChild(oElmntRoot);
                //Add the element to the xml document 
                loopNodes(oElmntRoot, this.tbxPath.Text);
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("创建自动更新列表文件失败:" ex.Message,Text);
                return false;
            }
        }

        private void loopNodes(XmlElement oElmntParent, string strPath)
        {
            DirectoryInfo ofs = new DirectoryInfo(strPath);

            //Files Loop ------------------------------------------------------ 
            this.pbBuild.Maximum = ofs.GetFiles().Length;
            this.pbBuild.Value = 0;

            foreach (FileInfo oFile in ofs.GetFiles())
            {
                if (oFile.Name != "AutoUpdateManifest.xml" 
                    & !oFile.Name.EndsWith(".pdb") 
                    & !oFile.Name.EndsWith(".config") 
                    & !oFile.Name.EndsWith(".vshost.exe") 
                    & !oFile.Name.EndsWith(".manifest")
                    & !oFile.Name.EndsWith(".cs")
                    & !oFile.Name.EndsWith(".user")
                    & !oFile.Name.EndsWith(".resx")
                    & !oFile.Name.EndsWith(".csproj")
                    & !oFile.Name.EndsWith(".suo"))
                {
                    XmlElement oElmntLeaf1 = default(XmlElement);
                    //Manipulates the files nodes 
                    XmlElement oElmntFileName = default(XmlElement);
                    XmlElement oElmntFileVersion = default(XmlElement);
                    XmlElement oElmntFileModified = default(XmlElement);

                    oElmntLeaf1 = xmlDoc.CreateElement("name");
                    oElmntLeaf1.SetAttribute("file", oFile.Name);
                    oElmntParent.AppendChild(oElmntLeaf1);

                    oElmntFileName = xmlDoc.CreateElement("filename");
                    oElmntFileName.InnerText = oFile.Name;
                    oElmntLeaf1.AppendChild(oElmntFileName);

                    FileVersionInfo fv = FileVersionInfo.GetVersionInfo(oFile.FullName);
                    oElmntFileVersion = xmlDoc.CreateElement("fileversion");
                    oElmntFileVersion.InnerText = fv.FileVersion;
                    oElmntLeaf1.AppendChild(oElmntFileVersion);

                    oElmntFileModified = xmlDoc.CreateElement("filelastmodified");
                    oElmntFileModified.InnerText = oFile.LastAccessTimeUtc.ToString();
                    oElmntLeaf1.AppendChild(oElmntFileModified);
                }
                this.pbBuild.Value  ;
                Application.DoEvents();
            }
        }
        #endregion

        #region Event

        private void btnBrowser_Click(object sender, EventArgs e)
        {
            fbdPath.Description = "请选择\r\n需要自动更新的文件所在的文件夹.";
            if (DialogResult.OK.Equals(this.fbdPath.ShowDialog()))
            {
                if (!this.fbdPath.SelectedPath.EndsWith(@"\"))
                {
                    this.fbdPath.SelectedPath  = @"\";
                }
                this.tbxPath.Text = this.fbdPath.SelectedPath;
            }
        }

        private void btnBuild_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.tbxPath.Text.Trim()))
            {
                this.Height  = 30;
                xmlDoc.RemoveAll();
                xmlDoc.AppendChild(xmlDoc.CreateProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"));
                if (createRootNode())
                {
                    xmlDoc.Save(tbxPath.Text   "AutoUpdateManifest.xml");
                    MessageBox.Show("自动更新文件列表文件:AutoUpdateManifest.xml\r\n已成功创建.\r\n" 
                    "请将该目录下的所有有用的文件(包括AutoUpdateManifest.xml,不含文件夹)复制到自动更新服务器根目录下的指定文件夹内.\r\n" 
                    "以便客户程序下载更新.", Text);
                    this.Height -= 30;
                }
            }
        }

        #endregion

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }



    }
}