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.
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.
Click the Firefox button to open the menu and click on Bookmarks. Click the Bookmarks menu and click on Show All Bookmarks.
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.
Use the SQLite driver for .Net and access the file places.sqlite it can be found atApplication 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With