Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read Firefox bookmarks using C#

Using C#, I need to get all Firefox bookmarks for importing them into our database. How can I do this?

I'm aware of the SO question, Read FF 3 bookmarks in Java, but the answers there all seem to revolve around Java database drivers, and I'm not sure that some of those answers aren't Java-specific.

My primary question is, "How can I read Firefox bookmarks in C#?"

Secondary questions: I see \%user profile%\application data\mozilla\firefox\profiles\bookmarkbackups\bookmarks-[date].json files -- can I just parse that? If so, are there any existing parsers for that?

Rhetorical lamenting question: Why can't this be as easy as IE, where I just read the .url files in \%user profile%\favorites? Bah.

like image 961
Judah Gabriel Himango Avatar asked Jun 03 '09 15:06

Judah Gabriel Himango


People also ask

Where are Firefox bookmarks in C drive?

Your Bookmarks (and History) are stored in a single file, places. sqlite, in your Profile folder. To open your Profile folder, Help > Troubleshooting Information , then next to "Profile Directory" click the "Open Containing Folder" button to open the Profile Folder.

How do I get a list of bookmarks in Firefox?

Click the Firefox button to open the menu and click on Bookmarks. Click the Bookmarks menu and click on Show All Bookmarks.

How do I transfer my Firefox bookmarks to a new computer?

On your laptop or home machine, in Firefox, go to Bookmarks->Organize Bookmarks. Then click on the Import/Export Button (Mac), Import and Backup Button (Windows/Linux) and select Export HTML. Save the file. Transfer that file to your office computer via e-mail, ssh, usb key, etc.


2 Answers

Use the SQLite driver for .Net and access the file places.sqlite it can be found at
Application Data/Mozilla/Firefox/Profiles/$this_varies/places.sqlite
on my computer. It should not be hard for you to locate on your target computers.


Edit 1:
Here is a snip of code that prints out urls from the database:

using System.Data.SQLite; // downloaded from http://sourceforge.net/projects/adodotnetsqlite

namespace sqlite_test
{
    class Program
    {
        static void Main(string[] args)
        {
            var path_to_db = @"C:\places.sqlite"; // copied here to avoid long path
            SQLiteConnection sqlite_connection = new SQLiteConnection("Data Source=" + path_to_db + ";Version=3;New=True;Compress=True;");

            SQLiteCommand sqlite_command = sqlite_connection.CreateCommand();

            sqlite_connection.Open();

            sqlite_command.CommandText = "select * from moz_places";

            SQLiteDataReader sqlite_datareader = sqlite_command.ExecuteReader();

            while (sqlite_datareader.Read())
            {
                // Prints out the url field from the table:
                System.Console.WriteLine(sqlite_datareader["url"]);
            }
        }
    }
}

Edit 2:
As tip. I really must recommend the SQLite Manager plugin for firefox. It's very useful for working with sqlite databases.

like image 110
Nifle Avatar answered Oct 08 '22 19:10

Nifle


Surely it works the same way as suggested in the Java question, just get the SQLite .NET provider and use that to access the FF database file.

like image 20
Tom van Enckevort Avatar answered Oct 08 '22 20:10

Tom van Enckevort