Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically locate my Dropbox folder using C#?

Tags:

c#

dropbox

How do I programmatically locate my Dropbox folder using C#? * Registry? * Environment Variable? * Etc...

like image 685
Jamey McElveen Avatar asked Mar 12 '12 00:03

Jamey McElveen


People also ask

How do I find the location of a Dropbox folder?

After you install the Dropbox desktop app, you can find the default location of Dropbox in your File Explorer (Windows) or Finder (Mac). It will be named “Dropbox”. Open Windows Explorer. Type %HOMEPATH%/Dropbox into the address bar.


1 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!

like image 84
Reinaldo Avatar answered Sep 23 '22 10:09

Reinaldo