Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            BookmarkDocument bookmark = new BookmarkDocument();

            bookmark.Load(@"D:\\bookmarks.html");
            bookmark.Save(@"d:\b.xml");
            Console.WriteLine("分析保存完毕...");
            XmlNodeList folders = bookmark.DocumentElement.SelectNodes("//folder");
            XmlNodeList links   = bookmark.DocumentElement.SelectNodes("//a");

            Console.WriteLine("共{0}个文件夹, {1}条网址", folders.Count, links.Count);
            Console.WriteLine("其中根目录有{0}个文件夹, {1}条网址", bookmark.RootFolder.ChildFolders.Count, bookmark.RootFolder.Links.Count);
            Console.ReadKey();
            //枚举一级文件夹
            foreach (BookmarkFolder folder in bookmark.RootFolder.ChildFolders)
            {
                Console.WriteLine("文件夹: {0}, 包含 {1} 条网址和 {2} 个子文件夹.", folder.Name, folder.Links.Count, folder.ChildFolders.Count);
            }
            Console.ReadKey();
            //枚举全部网址
            foreach (BookmarkLink link in bookmark.RootFolder.AllChildLinks)
            {
                Console.WriteLine("网址: {0} (Tag: {1})", link.Title, link.Tag);
            }
            Console.ReadKey();
        }
Ejemplo n.º 2
0
 protected void btnUpload_Click(object sender, EventArgs e)
 {
     if (fileFavorites.HasFile)
     {
         //创建收藏夹备份解释器
         BookmarkDocument doc = new BookmarkDocument();
         doc.Load(fileFavorites.FileContent);
         //获取当前用户
         BookmarkUser user = BookmarkContext.GetCurrentUser();
         //导入用户收藏夹
         user.Import(doc);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 导入收藏夹
        /// </summary>
        /// <param name="document"></param>
        public void Import(BookmarkDocument document)
        {
            List <Hashtable>    fieldsList = new List <Hashtable>();
            List <BookmarkLink> links      = document.RootFolder.AllChildLinks;

            foreach (BookmarkLink link in links)
            {
                //获取一条数据库空行
                Hashtable fields = FavorField.EmptyRow();
                fields[FavorField.Username] = Username;
                fields[FavorField.Title]    = link.Title.Length > 250 ? link.Title.Substring(0, 250) : link.Title;
                fields[FavorField.Href]     = link.Href;
                fields[FavorField.Tag]      = link.Tag;
                fieldsList.Add(fields);
            }
            //批量添加
            long[] idList = Favors.Add(fieldsList.ToArray());
            Console.WriteLine("Insert ID Count: {0}", idList.Length);
        }