Click here to Skip to main content
13,357,773 members (74,687 online)
Click here to Skip to main content
Add your own
alternative version


35 bookmarked
Posted 14 Sep 2007

How to Parse the Bookmarks File of Mozilla into a Datatable

, 14 Sep 2007
Rate this:
Please Sign up or sign in to vote.
An article describing how to parse a Mozilla bookmarks file into a datatable
Screenshot - ImportMozilla1.jpg


In this article, I create a procedure to import the file HTML containing the favourites of Mozilla Firefox. It is useful for parsing the file, putting it into a DataTable and then putting it into a TreeView. You can import Mozilla Firefox favourites to your application with this class.

Using the Code

Essentially, the file is an HTML file with particular tags to identify the URLs and folders. When you meet the tag <DT> followed by <H3>, it means that a new folder starts. I used a static method from the class ClsMozilla called ReadBookmark that returns a DataTable, accepting as a parameter the physical name of the file containing the bookmarks. I used StreamReader StreamBookMarks to make a cycle in order to analyze all the rows contained in the file. When I met the relevant tag, I placed the Folder and Links in the DataTable.

int Last_parent_id = 0;
//this is the relation with a folder. 0 means that it is alone
int Before_parent_id = 0;
//when close the folder, this store the prev id

This is done in order to associate each link or folder with a parent folder. This is fundamental when you want to build the tree of the links because you need to know the parent. This is interesting use of the DataTable because, in the first round, I tried to use a multidimensional array, but the management of this last is really more difficult than a DataTable. In the DataTable, I created various columns.

DataTable dt = new DataTable();
dt.Columns.Add( new DataColumn("id", typeof(Int32)));
dt.Columns.Add( new DataColumn("parent_id", typeof(Int32)));
dt.Columns.Add( new DataColumn("Hierarchy", typeof(Int32)));
dt.Columns.Add(new DataColumn("Title", typeof(string)));
dt.Columns.Add(new DataColumn("Link", typeof(string)));
dt.Columns.Add(new DataColumn("Des", typeof(string)));
dt.Columns.Add(new DataColumn("Type", typeof(string)));
DataRow dr ;

In the variable Type, I trace the nature of the link, i.e. if it is a URL or a Folder. I used a simple Regex to remove the HTML code.

public static string StripHTMLTags(string StrText)
//On retire le code HTML
return Regex.Replace(StrText,@"<(.|\n)*?>",string.Empty);

Points of Interest

The class is very simple, as is the Firefox file's structure. The favourites of Internet Explorer are simpler because every favourite is a simple file. The Opera bookmark file is similar to Firefox and, in the future, I will release a new article for the other browser.


  • 14 September, 2007 -- Original version posted


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Pierpaolo Romanelli
Web Developer
Italy Italy
I am a professional developer in Milan, I wrote many software and site for firm and bank, I like programming because I think it is an art!
My site is and

You may also be interested in...


Comments and Discussions

QuestionAwesome! Pin
thund3rstruck2-Nov-14 9:31
memberthund3rstruck2-Nov-14 9:31 
AnswerRe: Awesome! Pin
Pierpaolo Romanelli24-Apr-15 9:59
memberPierpaolo Romanelli24-Apr-15 9:59 
GeneralRe: Awesome! Pin
RagTopMan3-Aug-15 13:45
memberRagTopMan3-Aug-15 13:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 14 Sep 2007
Article Copyright 2007 by Pierpaolo Romanelli
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid