最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

c#批量整理xml格式示例

 更新時間:2014年03月04日 16:49:46   作者:  
這篇文章主要介紹了c#批量整理xml格式示例,win7的x64和x86系統(tǒng)下已驗證通過,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

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;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (listBox1.Items.Count == 0)
            {
                MessageBox.Show("no file name ");
            }
            else
            {
                func_SearchFiles(sender, e);//取得文件名
            }
            //listBox1.Items.Clear();
        }
        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
            listBox1.Items.Add ( path);//顯示文件夾目錄

        }

        private void Form1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
                e.Effect = DragDropEffects.Link;
            else
                e.Effect = DragDropEffects.None;
        }

        private void func_SearchFiles(object sender, EventArgs e)
        {
            // 獲取指定文件夾目錄
            string filepath = listBox1.Items[0].ToString();
            DirectoryInfo baseDir = new DirectoryInfo(filepath);
            // 獲取指定文件夾下的所有文件。
            // 如果你需要獲取特定格式的文件,如.html 結(jié)尾的,可以寫成 baseDir.GetFiles("*.html");
            FileInfo[] files = baseDir.GetFiles("*.xml");
            // 定義文件名字符串
            progressBar1.Visible = true;
            progressBar1.Maximum = files.Length;
            progressBar1.Minimum = 0;
            string fileNames = string.Empty;
            for (int i = 0; i < files.Length; i++)
            {
                // 獲取每個文件名,并記錄到 字符串 fileNames 里
                // 如果需要獲取文件的完整路徑名, files[i].FullName;
                //fileNames += files[i].FullName + ",";

                string xmlfile = @files[i].FullName;
                MemoryStream mstream = new MemoryStream(1024);
                XmlTextWriter writer = new XmlTextWriter(mstream, null);
                XmlDocument xmldoc = new XmlDocument();
                writer.Formatting = Formatting.Indented;
                xmldoc.Load(xmlfile);
                xmldoc.WriteTo(writer);
                writer.Flush();
                writer.Close();
                Encoding encoding = Encoding.GetEncoding("utf-8");
                listBox1.Items.Add("正在處理:" + @files[i].FullName);
                listBox1.SelectedIndex = listBox1.Items.Count - 1;
                progressBar1.Value = i+1;
                //this.ListBox1.Text += "\r\n正在處理:" + @files[i].FullName + "...\r\n";
                //File myfile = new file
                xmldoc.Save(@files[i].FullName);
                mstream.Close();
            }
            // 顯示到 Label 標(biāo)簽上
            listBox1.Items.Add("Finish!!!!");
            listBox1.SelectedIndex = listBox1.Items.Count - 1;
        }

        private void button2_Click(object sender, EventArgs e)
        {

           // this.listBox1.SelectedItem = listBox1.Items.IndexOf(0);//保持文本顯示在最后一行
            listBox1.Items.Clear();
            progressBar1.Visible = false;
            progressBar1.Value = 0;
        }

    }
}

相關(guān)文章

  • C#使用FolderBrowserDialog類實現(xiàn)選擇打開文件夾方法詳解

    C#使用FolderBrowserDialog類實現(xiàn)選擇打開文件夾方法詳解

    這篇文章主要介紹了C#選擇文件夾/打開文件夾/瀏覽文件夾等代碼方法,大家參考使用
    2013-11-11
  • 最新評論

    林甸县| 新乡市| 玉树县| 抚远县| 绥江县| 个旧市| 平塘县| 罗甸县| 咸阳市| 囊谦县| 威海市| 隆回县| 开化县| 崇文区| 吉隆县| 五家渠市| 广元市| 龙口市| 江口县| 永昌县| 连城县| 普定县| 保山市| 泗水县| 沙洋县| 曲阜市| 泸定县| 塔河县| 肥乡县| 乡城县| 北宁市| 新绛县| 讷河市| 边坝县| 双流县| 麻城市| 岳普湖县| 宜城市| 芜湖市| 五原县| 林西县|