1
votes

The path of firefox history file contain a Profile Number how can i get this number dynamically in C#

C:\Users\\AppData\Roaming\Mozilla\Firefox\Profiles\.default\formhistory.sqlite

3

3 Answers

1
votes

You can read out the following ini file which contains the profile names of every firefoxprofile:

"C:\Users\Username\AppData\Roaming\Mozilla\Firefox\profiles.ini"
1
votes

you need to read profiles.ini file and catch the default profile

using System;
using System.Linq;
using System.IO;

namespace Firefox
{
    class Reader
    {
        public static string ReadFirefoxProfile()
        {
            string apppath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            string mozilla = System.IO.Path.Combine(apppath, "Mozilla");

            bool exist = System.IO.Directory.Exists(mozilla);

            if (exist)
            {

                string firefox = System.IO.Path.Combine(mozilla, "firefox");

                if (System.IO.Directory.Exists(firefox))
                {
                    string prof_file = System.IO.Path.Combine(firefox, "profiles.ini");

                    bool file_exist = System.IO.File.Exists(prof_file);

                    if (file_exist)
                    {
                        StreamReader rdr = new StreamReader(prof_file);

                        string resp = rdr.ReadToEnd();

                        string[] lines = resp.Split(new string[] { "\r\n" }, StringSplitOptions.None);

                        string location = lines.First(x => x.Contains("Path=")).Split(new string[] { "=" }, StringSplitOptions.None)[1];

                        string prof_dir = System.IO.Path.Combine(firefox, location);

                        return prof_dir;
                    }
                }
            }
            return "";
        }
    }
}
-1
votes

Click the Windows Start button and type %APPDATA%\Mozilla\Firefox\Profiles\ in the Search box at the bottom of the Start menu, without pressing Enter. A list of profiles will appear at the top of the Start menu.
Click on the profile with “default” in the name to open it in a window.