Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get path to dropbox folder on different computer

Posted on 2013-11-12
12
Medium Priority
?
2,167 Views
Last Modified: 2013-11-14
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
Comment
Question by:jb702
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
12 Comments
 
LVL 85
ID: 39644668
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
 
LVL 20

Accepted Solution

by:
ltlbearand3 earned 2000 total points
ID: 39644902
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
 

Author Closing Comment

by:jb702
ID: 39645088
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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 85
ID: 39645208
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
 

Author Comment

by:jb702
ID: 39645237
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
 
LVL 20

Expert Comment

by:ltlbearand3
ID: 39646654
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
 
LVL 85
ID: 39646703
"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
 
LVL 20

Expert Comment

by:ltlbearand3
ID: 39646755
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
 
LVL 85
ID: 39647516
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
 
LVL 20

Expert Comment

by:ltlbearand3
ID: 39647859
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
 
LVL 85
ID: 39648298
I just installed it a few days ago (I don't really use DropBox), so perhaps it is outdated?
0
 
LVL 20

Expert Comment

by:ltlbearand3
ID: 39650065
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

Featured Post

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question