首页 > Web开发 > 详细

C# 批量规范HTML工具

时间:2014-08-25 16:36:34      阅读:359      评论:0      收藏:0      [点我收藏+]

1、问题描述:

由为知笔记导出的文件导入Evernote的时候,有一些(新建的)HTML文件以<mate>标签开头,查阅Evernote的log可知因此文件不能被导入。

责任无论归于为知还是Evernote都不重要,总之几百篇日志不可能通过复制粘贴进行导入。

 

2、工具解决问题:

批量将某一文件夹内不合规范html文件规范化。

 

3、界面

bubuko.com,布布扣

 

4、主要代码

private void button2_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                DirectoryInfo dir = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
                FileInfo[] files = dir.GetFiles("*.html");
                for (int i = 0; i < files.Length; i++)
                {
                    System.IO.StreamReader sr = new System.IO.StreamReader(files[i].DirectoryName+"\\"+files[i].ToString());
                    NSoup.Nodes.Document doc = NSoup.NSoupClient.Parse(sr.ReadToEnd());
                    try
                    {
                        sr.Dispose();
                        File.Delete(files[i].DirectoryName + "\\" + files[i].ToString());
                        using (StreamWriter sw = new StreamWriter(files[i].DirectoryName+"\\"+files[i].ToString(), false, System.Text.Encoding.GetEncoding("UTF-8"))) //保存地址
                        {
                            sw.WriteLine(doc.ToString());
                            sw.Flush();
                            sw.Close();
                        }
                    }
                    catch
                    {

                    } 
                }
                Application.Exit();
            }
        }

5、源码:

环境:vs2008

组件:Nsoup.dll

http://app.yinxiang.com/shard/s12/sh/e4ef4bd5-703b-41ba-9603-6f5fbd2934b1/690319451be72d6897f434e485d45de7

C# 批量规范HTML工具

原文:http://www.cnblogs.com/yixiaozi/p/3935167.html

(0)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!