实例介绍
【实例简介】
【实例截图】
【核心代码】
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();
}
}
}
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论