C# 批量規範HTML工具

來源:互聯網
上載者:User

標籤:des   style   blog   http   os   io   檔案   for   ar   

1、問題描述:

由為知筆記匯出的檔案匯入Evernote的時候,有一些(建立的)HTML檔案以<mate>標籤開頭,查閱Evernote的log可知因此檔案不能被匯入。

責任無論歸於為知還是Evernote都不重要,總之幾百篇日誌不可能通過複製粘貼進行匯入。

 

2、工具解決問題:

批量將某一檔案夾內不合規範html檔案規格化。

 

3、介面

 

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工具

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.