Link to home
Start Free TrialLog in
Avatar of jb702
jb702

asked on

Get path to dropbox folder on different computer

I am looking for a way to programmatically find the path of the "Dropbox" folder within a PC.

I ran accross this code for C+, but don't know how to convert it to VBA, if that is possible at all.

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.ASCII.GetString(dbBase64Text);

        return folderPath;
    }
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

That code looks for the path to the "ApplicationData" folder on the machine, and then combines that with "Dropbox\\host.db", which apparently points to the Dropbox folder.

You can use the Environ command to get the AppData path:

Dim sAppData As String
sAppData = Environ("AppData") & "\DropBox\host.db"

"host.db" is an SQLite database, so you'd have to be able to read that file. You'd need the SQLite drivers installed on the remote machine. Also, if the user left the DropBox folder at the "default" location, you couldn't read from host.db - it would be in <users>\My Documents\DropBox.
ASKER CERTIFIED SOLUTION
Avatar of ltlbearand3
ltlbearand3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jb702
jb702

ASKER

Wow, that is fricken awesome. Thank you. i could imagine i could use this function for others means as well. thank you so much.
I tried the code on my machine (with DropBox installed, and with a non-default DropBox folder defined) and it errored out. Did it work for you? Just curious really ...
Avatar of jb702

ASKER

Yeah, i think mine is in the default location.

"C:\Users\Jbryan\Desktop\Dropbox\"

Was this where yours was at?

I have a users  machine where it is located at

"C:\Users\Joe\Dropbox\"

Hmmm.
Glad it worked for you.

@LMSConsulting - Since I don't have dropbox, I can't test this too well.  I know you are just curious and if you want to pursue getting this work, we can look at it - to make the code better.  If we pursue, I am wondering where it errors at.  I know the Environ("AppData") does not always pull in values on some windows boxes, but it works most of the time and it simpler code.  I wonder if that is returning a blank value and therefore an invalid path.
"C:\Users\Jbryan\Desktop\Dropbox\"

I believe that is the default.

I am wondering where it errors at

Right here:

Base64Decode = StrConv(objNode.nodeTypedValue, vbUnicode)

When that line is run, the value of objNode.nodeTypedValue results in "The parameter is incorrect"
Hmm.  I am able to test that part of the code and it works.  What version of Microsoft XML is referenced in the project?  I was running in Excel 2010 to use that VBA editor.  What are you testing the code in?  

If you add this line of code in sub test, does it work?  [Should put ThisIsATest in the immediate window.
    Debug.Print Base64Decode("VGhpc0lzQVRlc3Q=")

Open in new window


-Bear
XML 6.0, and I'm running this in Access 2010.

If I run that line in the Immediate window, I get "ThisIsATest", so it would seem your Base64Decode routine functions as expected.
It makes me wonder if your host.db is not base64 encoded.  Everything I read is that file is base64 encoded.  I wonder if you have a different db version and if maybe it has changed at some point.
I just installed it a few days ago (I don't really use DropBox), so perhaps it is outdated?
I don't know - or maybe they updated it.  Since I don't use it, I don't really know.  I am fairly certain it has something to do with host.db either being corrupt or encoded in a different manner.