How do I programmatically locate my Dropbox folder using C#? * Registry? * Environment Variable? * Etc...
-
Sorry - my comment was nonsense, hadn't noticed that the regkeys were pointing at the dropbox dll, not the dropbox location. Found this forum post but looks like it may not work: http://forums.dropbox.com/topic.php?id=47895 I'm personally doing the same as DankDank but would guess that this won't work on users personal installs if they change the default location. – David Hall Mar 12 '12 at 00:38
-
Have you tried using [Process Explorer](http://technet.microsoft.com/en-us/sysinternals/bb896653) during the install process to see what it does and what hints you can find to detect it? – M.Babcock Mar 12 '12 at 00:39
9 Answers
UPDATED SOLUTION
Dropbox now provides an info.json file as stated here: https://www.dropbox.com/en/help/4584
If you don't want to deal with parsing the JSON, you can simply use the following solution:
var infoPath = @"Dropbox\info.json";
var jsonPath = Path.Combine(Environment.GetEnvironmentVariable("LocalAppData"), infoPath);
if (!File.Exists(jsonPath)) jsonPath = Path.Combine(Environment.GetEnvironmentVariable("AppData"), infoPath);
if (!File.Exists(jsonPath)) throw new Exception("Dropbox could not be found!");
var dropboxPath = File.ReadAllText(jsonPath).Split('\"')[5].Replace(@"\\", @"\");
If you'd like to parse the JSON, you can use the JavaScripSerializer as follows:
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var dictionary = (Dictionary < string, object>) serializer.DeserializeObject(File.ReadAllText(jsonPath));
var dropboxPath = (string) ((Dictionary < string, object> )dictionary["personal"])["path"];
DEPRECATED SOLUTION:
You can read the the dropbox\host.db file. It's a Base64 file located in your AppData\Roaming path. Use this:
var dbPath = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Dropbox\\host.db");
var dbBase64Text = Convert.FromBase64String(System.IO.File.ReadAllText(dbPath));
var folderPath = System.Text.ASCIIEncoding.ASCII.GetString(dbBase64Text);
Hope it helps!

- 4,556
- 3
- 24
- 24
-
5Use `System.Text.Encoding.UTF8.GetString(dbBase64Text)`. I had a user that had the path `C:\Users\Jörg\Dropbox` that would not read correctly if ASCII was used. – jimbojones Dec 11 '13 at 16:25
-
1Anyone uses this code: if you got junk data before the path, check [ivanatpr's answer](http://stackoverflow.com/a/10401659/348336) below. – Gildor May 26 '15 at 04:35
-
This method stopped working in later versions of dropbox. My answer below show the current way to do this. – Derek Jun 19 '16 at 00:57
-
I've updated the answer with the latest solution alternatives. Thank you for pointing this out @Derek. – Reinaldo Jun 30 '16 at 13:55
-
Note that if you have Dropbox Business edition, the JSON is dictionary["business"])["path"], thus a more flexible solution might be dictionary[dictionary.Keys.FirstOrDefault()])["path"]. Admittedly a bit clunky, but you get the idea. – dlchambers Jun 21 '18 at 14:25
UPDATE JULY 2016: THE CODE BELOW NO LONGER WORKS DUE TO CHANGES IN THE DROPBOX CLIENT, SEE ACCEPTED ANSWER ABOVE FOR UP-TO-DATE SOLUTION
Reinaldo's answer is essentially correct but it gives some junk output before the path because there seem to be two lines in the host.db file and in this case you only want to read the second one. The following will get you just the path.
string appDataPath = Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData);
string dbPath = System.IO.Path.Combine(appDataPath, "Dropbox\\host.db");
string[] lines = System.IO.File.ReadAllLines(dbPath);
byte[] dbBase64Text = Convert.FromBase64String(lines[1]);
string folderPath = System.Text.ASCIIEncoding.ASCII.GetString(dbBase64Text);
Console.WriteLine(folderPath);

- 1,862
- 14
- 18
-
1This method appears to no longer work with recent versions of Dropbox. Please refer to the accepted answer for an updated solution. – Reinaldo Jun 30 '16 at 13:57
-
ok thanks for the heads up, edited answer to add a disclaimer that it's outdated – ivanatpr Jul 06 '16 at 03:04
Cleaner version based on previous answers (use var, added exists check, remove warnings):
private static string GetDropBoxPath()
{
var appDataPath = Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData);
var dbPath = Path.Combine(appDataPath, "Dropbox\\host.db");
if (!File.Exists(dbPath))
return null;
var lines = File.ReadAllLines(dbPath);
var dbBase64Text = Convert.FromBase64String(lines[1]);
var folderPath = Encoding.UTF8.GetString(dbBase64Text);
return folderPath;
}

- 63,284
- 17
- 238
- 185
This seems to be the suggested solution from Dropbox: https://www.dropbox.com/help/4584?path=desktop_client_and_web_app

- 3,596
- 2
- 21
- 23
-
Yes. This should be the accepted answer. The `host.db` file is not created by newer versions of Dropbox. The old method of reading `hosts.db` may work on your machine because no Dropbox update bothered to delete the file. – Rocky Scott Dec 18 '15 at 14:45
Dropbox has added a new helper, there is a JSON file in either %APPDATA%\Dropbox\info.json
or %LOCALAPPDATA%\Dropbox\info.json
.
See https://www.dropbox.com/help/4584 for more information.

- 66
- 3
-
Should have put sample code in to read this and you might get more upvotes and accepted as the answer. – DermFrench Sep 28 '15 at 13:02
public static string getDropBoxPath()
{
try
{
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var dbPath = Path.Combine(appDataPath, "Dropbox\\host.db");
if (!File.Exists(dbPath))
{
return null;
}
else
{
var lines = File.ReadAllLines(dbPath);
var dbBase64Text = Convert.FromBase64String(lines[1]);
var folderPath = Encoding.UTF8.GetString(dbBase64Text);
return folderPath;
}
}
catch (Exception ex)
{
throw ex;
}
}

- 11
- 2
I'm posting here a solution that does not use Dictionary; so many years after original answers, every time that I try to use answers from Reinaldo and Derek, I get a Could not load type 'System.Web.Util.Utf16StringValidator' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=... using both LinqPad 7 (.NET 6.0.9) and VS 2022 (Net Standard 2.0),
I do not know if this error is because I'm already referencing Newtonsoft.Json in Assembly as suggested in this unaccepted answer.
Anyway, here is 2022 piece of cake way to do it:
private static string GetDropBoxPath()
{
// https://www.dropbox.com/en/help/4584 says info.json file is in one of two places
string jsonPath = Environment.ExpandEnvironmentVariables(@"%LOCALAPPDATA%\Dropbox\info.json");
if (!File.Exists(jsonPath)) jsonPath = Environment.ExpandEnvironmentVariables(@"%APPDATA%\Dropbox\info.json");
var dropbox = JsonConvert.DeserializeObject<DropboxRoot>(File.ReadAllText(jsonPath));
return dropbox.personal.path;
}
And these are the auxiliary classes:
public class DropboxRoot
{
public Personal personal { get; set; }
}
public class Personal
{
public string path { get; set; }
public long host { get; set; }
public bool is_team { get; set; }
public string subscription_type { get; set; }
}

- 590
- 1
- 7
- 24
The host.db method has stopped working in later versions of dropbox.
https://www.dropbox.com/en/help/4584 gives the recommended approach.
Here is the c# code I wrote to parse the json and get the dropbox folder.
// https://www.dropbox.com/en/help/4584 says info.json file is in one of two places
string filename = Environment.ExpandEnvironmentVariables( @"%LOCALAPPDATA%\Dropbox\info.json" );
if ( !File.Exists( filename ) ) filename = Environment.ExpandEnvironmentVariables( @"%APPDATA%\Dropbox\info.json" );
JavaScriptSerializer serializer = new JavaScriptSerializer();
// When deserializing a string without specifying a type you get a dictionary <string, object>
Dictionary<string, object> obj = serializer.DeserializeObject( File.ReadAllText( filename ) ) as Dictionary<string, object>;
obj = obj[ "personal" ] as Dictionary<string, object>;
string path = obj[ "path" ] as string;
return path;

- 7,615
- 5
- 33
- 58
It's not stored in the registry (at least it isn't in plain text). I believe it's stored in the following location.
C:\Users\userprofile\AppData\Roaming\Dropbox
I would say it resides in the host.db or unlink.db file.
The config.db is a sqlite file. The other two are unknown (encrypted). The config.db contains a blob field only with the schema version.

- 2,751
- 1
- 18
- 20