收藏夹文件bookmark.htm导入,读取

 

现在很多网站,比如网摘之类的网站,都支持从收藏夹文件导入到列表.其实这个过程并不复杂,下面是我的处理过程,拿来分享一下:

引入命名空间:using System.Text.RegularExpressions;

private
void Page_Load(object sender, System.EventArgs e)
        {
            string str = LoadFile("bookmark.htm");
            MatchCollection category = Regex.Matches(str, "<DT><H3 FOLDED(.+?)>(.+?)</H3>", RegexOptions.IgnoreCase | RegexOptions.Multiline );
            foreach(Match m in category)
            {
                this.Label1.Text+=m.Groups[0].Value;//显示分类
            }
            MatchCollection link=Regex.Matches(str,"<DT><A HREF=\"(.+?)\"(.+?)>(.+?)</A>", RegexOptions.IgnoreCase | RegexOptions.Multiline );
            foreach(Match n in link)
            {
                this.Label2.Text+=n.Groups[0].Value;//显示列表
            }
        }
        private string LoadFile(string file)
        {
            StringWriter sw = new StringWriter ();
             Server.Execute (file, sw);
             string content = sw.ToString ();
            return content;
        }

posted @ 2007-01-11 14:49  '.Elvis.'  阅读(1799)  评论(1编辑  收藏  举报