DropBox is a great little service that simply “just works”. If you have a DropBox account and wishes to operate this from code, you have to know a great deal about REST and other “webby” stuff to communicate with the DropBox account. But, a great little library exists that shields you from all of this. On “github” (what ever that means?) ) you will find the DropNet library that helps you out here. It will allow you to operate the DropBox account quite easily.
How to do ?
1) Register a developer account at Dropbox.com
2) Obtain the ‘key’ and ‘secret’ from DropBox.com (found under ‘My Apps’)
3) Call into the users DropBox account like below
//client
var client = new DropNet.DropNetClient("u1liluz34reo50t", "werfrewdf9zdptb4u");
//login
client.Login("user@domain.com", "password");
//get root data
var data = client.GetMetaData(string.Empty);
Console.WriteLine("Path = {0}", data.Path);
data.Contents.ForEach(x => Console.WriteLine("name = {0}", x.Name)); //write out all folders/files
As you can see in the sample, you create a DropNetClient instance providing the ‘key’ and ‘secret’. Next you simply login using the User id (email) and password. GetMetaData(string.empty) is a method call for retrieving all entries from the root-folder. Every ‘metadata’ contains a boolen property (.IsDirectory) that allows you to determine whether you are handling a folder or a file.
No comments:
Post a comment