Dropbox - Listing files

Submitted by Karthikeyan on Aug 06, 2013 - 20:40
Before using this code make sure you added necessary references to sharpbox dll files and you generated the token file(SharpDropBox.Token) using Dropbox Token Issuer Tool (Revised) for Sharpbox.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using AppLimit.CloudComputing.SharpBox;
using AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox;

namespace StatsUploader
{
    class ListDropboxFiles
    {
        public String ListFiles()
        {
            String msg = "";
            // Creating the cloudstorage object    
            CloudStorage dropBoxStorage = new CloudStorage();
            // get the configuration for dropbox 
            var dropBoxConfig =
            CloudStorage.GetCloudConfigurationEasy(nSupportedCloudConfigurations.DropBox);
            // declare an access token 
            ICloudStorageAccessToken accessToken = null;

            // load a valid security token from file             
            using (FileStream fs = File.Open("SharpDropBox.Token", FileMode.Open, FileAccess.Read, FileShare.None))
            {
                accessToken = dropBoxStorage.DeserializeSecurityToken(fs);
            }
            // accessToken = Token;
            // open the connection  
                                    
            var storageToken = dropBoxStorage.Open(dropBoxConfig, accessToken);
                                   
            //List Files
                      
            var root = dropBoxStorage.GetRoot();
            // enumerate all child (folder and files) 
           
            if (root == null)
            {
                msg = msg + "No root object found";
            }
            else
            {
                foreach (ICloudFileSystemEntry fsentry in root)
                {
                    if (fsentry is ICloudDirectoryEntry)
                    {
                         msg = msg + fsentry.Name;
                    }
                    else
                    {
                         msg = msg + fsentry.Name;
                    }
                }
            }


            //

            // close the connection  
            dropBoxStorage.Close();
            return msg;
        }
    }
}