• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2347
  • Last Modified:

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;
    }
0
jb702
Asked:
jb702
  • 5
  • 5
  • 2
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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.
0
 
ltlbearand3Commented:
I don't use drop box, but your code appears to be reading the db file just by decoding the data using base64 decoding (and I see that elsewhere on the web).  I have taken the concepts above and converted them to VBA.  I used the FileSystemObject but there are other ways to access the data, if you like.  I also used XML to decode the base 64.  To use in VBA, you will need to add references to
Microsoft XML, v6.0
Microsoft Scripting RunTime

As LMSConsulting stated, you are assuming a path to the file that does not appear to be the default.  You may have to update that in the code.

' ExpertExchange Question ID28292626
' http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_28292626.html
' Expert: ltlbearand3 [http://www.experts-exchange.com/M_2469312.html]
'
' Requires the following references:
'   MICROSOFT SCRIPTING RUNTIME
'   MICROSOFT XML, V6.0

Public Sub Test()
    Debug.Print GetDropBoxPath
End Sub

Private Function GetDropBoxPath() As String
    
    On Error GoTo GetDropBoxPath_Error:
    
    ' Need a reference to Microsoft Scripting RunTime
    Dim objFSO As Scripting.FileSystemObject
    Dim objDropBox As Scripting.TextStream
    Dim strDropBoxFolder As String
    Dim strData() As String
    
    Set objFSO = New Scripting.FileSystemObject
    
    strDropBoxFolder = Environ("AppData") & "\DropBox\host.db"
    
    If objFSO.FileExists(strDropBoxFolder) Then
        Set objDropBox = objFSO.OpenTextFile(strDropBoxFolder, ForReading)
        objDropBox.SkipLine
        GetDropBoxPath = Base64Decode(objDropBox.ReadLine)
    End If
    
Release:
    On Error Resume Next
    Set objDropBox = Nothing
    Set objFSO = Nothing
    Exit Function

GetDropBoxPath_Error:

    Resume Release
    MsgBox "Procedure = GetDropBoxPath" & vbNewLine & _
        "Error Number = " & Err.Number & vbNewLine & _
        "Error Message = " & Err.Description & vbNewLine, _
        vbCritical Or vbSystemModal, "VBA Error"

End Function


Private Function Base64Decode(ByVal EncodedValue As String) As String

    On Error GoTo Base64Decode_Error:

    ' Uses XML to decode the Base 64 string
    ' Requires Reference to Microsoft XML, v6.0 or higher
    Dim objXMLDoc As MSXML2.DOMDocument60
    Dim objNode As MSXML2.IXMLDOMElement

    Set objXMLDoc = New MSXML2.DOMDocument60
    Set objNode = objXMLDoc.createElement("Base64")
    objNode.DataType = "bin.base64"
    objNode.Text = EncodedValue
    
    ' Convert byte array to string and return the string
    Base64Decode = StrConv(objNode.nodeTypedValue, vbUnicode)

Release:
    Set objNode = Nothing
    Set objXMLDoc = Nothing
    
    Exit Function

Base64Decode_Error:
    MsgBox "Procedure = Base64Decode" & vbNewLine & _
        "Error Number = " & Err.Number & vbNewLine & _
        "Error Message = " & Err.Description & vbNewLine, _
        vbCritical Or vbSystemModal, "VBA Error"
        
    Resume Release
End Function

Open in new window

-Bear
0
 
jb702Author Commented:
Wow, that is fricken awesome. Thank you. i could imagine i could use this function for others means as well. thank you so much.
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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 ...
0
 
jb702Author Commented:
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.
0
 
ltlbearand3Commented:
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.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
"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"
0
 
ltlbearand3Commented:
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
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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.
0
 
ltlbearand3Commented:
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.
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I just installed it a few days ago (I don't really use DropBox), so perhaps it is outdated?
0
 
ltlbearand3Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now