• 大小: 182KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-11
  • 语言: C#
  • 标签: C#  Winform  

资源简介

注释很详细 在网上看了看,对于新手来说很困难 所以我这个新手就写了写 测试通过 原创!

资源截图

代码片段和文件信息

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  xmlOperation\xmlOperation\bin\Debug\xmlOperation.exe

     文件      34304  2011-05-06 16:26  xmlOperation\xmlOperation\bin\Debug\xmlOperation.pdb

     文件       5632  2005-11-11 22:25  xmlOperation\xmlOperation\bin\Debug\xmlOperation.vshost.exe

     文件      14211  2011-05-06 16:22  xmlOperation\xmlOperation\Form1.cs

     文件      15589  2011-05-06 15:26  xmlOperation\xmlOperation\Form1.Designer.cs

     文件     155634  2011-05-06 15:26  xmlOperation\xmlOperation\Form1.resx

     文件        900  2011-05-06 15:26  xmlOperation\xmlOperation\obj\Debug\xmlOperation.csproj.GenerateResource.Cache

     文件     131072  2011-05-06 16:26  xmlOperation\xmlOperation\obj\Debug\xmlOperation.exe

     文件     100244  2011-05-06 15:26  xmlOperation\xmlOperation\obj\Debug\xmlOperation.Form1.resources

     文件      34304  2011-05-06 16:26  xmlOperation\xmlOperation\obj\Debug\xmlOperation.pdb

     文件        180  2011-05-06 09:10  xmlOperation\xmlOperation\obj\Debug\xmlOperation.Properties.Resources.resources

     文件       1159  2011-05-06 16:27  xmlOperation\xmlOperation\obj\xmlOperation.csproj.FileListAbsolute.txt

     文件        471  2011-05-06 09:09  xmlOperation\xmlOperation\Program.cs

     文件       1196  2011-05-06 09:09  xmlOperation\xmlOperation\Properties\AssemblyInfo.cs

     文件       2880  2011-05-06 09:09  xmlOperation\xmlOperation\Properties\Resources.Designer.cs

     文件       5612  2011-05-06 09:09  xmlOperation\xmlOperation\Properties\Resources.resx

     文件       1097  2011-05-06 09:09  xmlOperation\xmlOperation\Properties\Settings.Designer.cs

     文件        249  2011-05-06 09:09  xmlOperation\xmlOperation\Properties\Settings.settings

     文件       3231  2011-05-06 12:32  xmlOperation\xmlOperation\xmlOperation.csproj

     文件        925  2011-05-06 09:10  xmlOperation\xmlOperation.sln

    ..A..H.      9216  2011-05-06 15:15  xmlOperation\xmlOperation.suo

     目录          0  2011-05-06 09:16  xmlOperation\xmlOperation\obj\Debug\Refactor

     目录          0  2011-05-06 09:10  xmlOperation\xmlOperation\obj\Debug\TempPE

     目录          0  2011-05-06 09:10  xmlOperation\xmlOperation\bin\Debug

     目录          0  2011-05-06 16:20  xmlOperation\xmlOperation\obj\Debug

     目录          0  2011-05-06 12:26  xmlOperation\xmlOperation\bin

     目录          0  2011-05-06 09:09  xmlOperation\xmlOperation\obj

     目录          0  2011-05-06 09:09  xmlOperation\xmlOperation\Properties

     目录          0  2011-05-06 16:22  xmlOperation\xmlOperation

     目录          0  2011-05-06 09:10  xmlOperation

............此处省略3个文件信息

评论

共有 条评论