資源簡介
注釋很詳細
在網上看了看,對于新手來說很困難
所以我這個新手就寫了寫
測試通過
原創!

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;
using?System.Drawing.Drawing2D;
using?System.xml;
namespace?xmlOperation
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????///?
????????///?點擊選擇按鈕
????????///?
????????///?
????????///?
????????private?void?btnSelect_Click(object?sender?EventArgs?e)
????????{
????????????//拋異常
????????????try
????????????{
????????????????//初始化OpenFileDialog類
????????????????OpenFileDialog?openxml?=?new?OpenFileDialog();
????????????????//默認選擇文件格式
????????????????openxml.Filter?=?“xml文件(*.xml)|*.xml“;
????????????????//打開窗口標題欄
????????????????openxml.title?=?“選擇xml文件“;
????????????????//禁止多選
????????????????openxml.Multiselect?=?false;
????????????????//第一次默認打開文件路徑
????????????????openxml.FilterIndex?=?1;
????????????????//打開的默認路徑
????????????????openxml.InitialDirectory?=?System.AppDomain.CurrentDomain.baseDirectory;
????????????????//是否選擇
????????????????if?(openxml.ShowDialog()?==?DialogResult.OK)
????????????????{
????????????????????//清楚txtxmlStr文本框上的路徑
????????????????????this.txtxmlStr.Clear();
????????????????????//賦值
????????????????????this.txtxmlStr.Text?=?openxml.FileName;
????????????????}
????????????}
????????????catch?(Exception?Ex)
????????????{
????????????????MessageBox.Show(Ex.Message?“系統提示“?MessageBoxButtons.OK?MessageBoxIcon.Error);
????????????}
????????}
????????///?
????????///?加載xml文件
????????///?
????????///?
????????///?
????????private?void?btnLoading_Click(object?sender?EventArgs?e)
????????{
????????????//獲取文件路徑
????????????string?FileName?=?this.txtxmlStr.Text.Trim();
????????????//判斷是否選擇了xml文件
????????????if?(““.Equals(FileName))
????????????{
????????????????MessageBox.Show(“請選擇你要操作的文件“?“系統提示“?MessageBoxButtons.OK?MessageBoxIcon.Error);
????????????????return;
????????????}
????????????treeView1.Nodes.Clear();//清空treeview
????????????xmlDocument?xdoc?=?new?xmlDocument();
????????????//加載xml文件
????????????xdoc.Load(FileName);
????????????//調用讀取xml文件轉換到treeview中
????????????BuildTree(xdoc.ChildNodes?treeView1.Nodes);
????????????lblShow.Text?=?“當前狀態:您正在操作“?+?System.IO.Path.GetFileNameWithoutExtension(FileName).ToString()?+?“文件“;
????????????lblShow.ForeColor?=?System.Drawing.Color.Red;
????????}
????????///?
????????///?lNodes“>xml節點
????????///樹的當前節點
????????///?
????????///?
????????///?
????????private?void?BuildTree(xmlNodeList?xmlNodes?TreeNodeCollection?treeNodes)
????????{
????????????string?sValue;
????????????for?(int?i
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????131072??2011-05-06?16:26??xm
?????文件??????34304??2011-05-06?16:26??xm
?????文件???????5632??2005-11-11?22:25??xm
?????文件??????14211??2011-05-06?16:22??xm
?????文件??????15589??2011-05-06?15:26??xm
?????文件?????155634??2011-05-06?15:26??xm
?????文件????????900??2011-05-06?15:26??xm
?????文件?????131072??2011-05-06?16:26??xm
?????文件?????100244??2011-05-06?15:26??xm
?????文件??????34304??2011-05-06?16:26??xm
?????文件????????180??2011-05-06?09:10??xm
?????文件???????1159??2011-05-06?16:27??xm
?????文件????????471??2011-05-06?09:09??xm
?????文件???????1196??2011-05-06?09:09??xm
?????文件???????2880??2011-05-06?09:09??xm
?????文件???????5612??2011-05-06?09:09??xm
?????文件???????1097??2011-05-06?09:09??xm
?????文件????????249??2011-05-06?09:09??xm
?????文件???????3231??2011-05-06?12:32??xm
?????文件????????925??2011-05-06?09:10??xm
????..A..H.??????9216??2011-05-06?15:15??xm
?????目錄??????????0??2011-05-06?09:16??xm
?????目錄??????????0??2011-05-06?09:10??xm
?????目錄??????????0??2011-05-06?09:10??xm
?????目錄??????????0??2011-05-06?16:20??xm
?????目錄??????????0??2011-05-06?12:26??xm
?????目錄??????????0??2011-05-06?09:09??xm
?????目錄??????????0??2011-05-06?09:09??xm
?????目錄??????????0??2011-05-06?16:22??xm
?????目錄??????????0??2011-05-06?09:10??xm
............此處省略3個文件信息
- 上一篇:酒店預訂管理系統系統結構圖
- 下一篇:C# socket實現簡單的聊天功能
評論
共有 條評論