Single C# API to access dropbox, iCloud, SkyDrive, etc.?

3.7k views Asked by At

I am looking for a way to read files from all the various cloud storage systems out there without writing code for each specific API. Is there a way to accomplish this? What we need is pretty simple:

  1. A way to get folder contents for a FileOpen dialog box.
  2. A way to read the selected file.
  3. Optional: a FileOpen dialog that does all the work to show the files and select one.

thanks - dave

2

There are 2 answers

0
punkdata On BEST ANSWER

There is a solution to this problem. point.io has a public api that brokers access to cloud & enterprise storage providers via restful api. It basically has the functionality you're looking for. The api enables developers to view the various storage providers as types and does all the heavy lifting for your app.

They have a github repo that has C# src code examples

Here is some simple C# code that calls a file list:

public async Task<List<FolderContent>> list(String sessionKey, String shareid, String containerid, String path)
{
HttpClient tClient = new HttpClient();
tClient.DefaultRequestHeaders.Add("AUTHORIZATION", sessionKey);
var query = HttpUtility.ParseQueryString(string.Empty);
query["folderid"] = shareid;
query["containerid"] = containerid;
query["path"] = path;
string queryString = query.ToString();
var rTask = await tClient.GetAsync(PointIODemo.MvcApplication.APIUrl + "folders/list.json?" + queryString);
var rContent = rTask.Content.ReadAsStringAsync().Result;
var oResponse = JsonConvert.DeserializeObject<dynamic>(rContent);
if (oResponse["ERROR"] == "1")
{
HttpContext.Current.Response.Redirect("/Home/ErrorTemplate/?errorMessage=" + oResponse["MESSAGE"]);
}
var rawColList = JsonConvert.DeserializeObject<List<dynamic>>(JsonConvert.SerializeObject(oResponse["RESULT"]["COLUMNS"]));
var rawContentList = JsonConvert.DeserializeObject<List<dynamic>>(JsonConvert.SerializeObject(oResponse["RESULT"]["DATA"]));
var fContentList = new List<FolderContent>();
foreach (var item in rawContentList)
{
FolderContent tContent = new FolderContent();
tContent.fileid = item[MvcApplication.getColNum("FILEID", rawColList)];
tContent.filename = item[MvcApplication.getColNum("NAME", rawColList)];
tContent.containerid = item[MvcApplication.getColNum("CONTAINERID", rawColList)];
tContent.remotepath = item[MvcApplication.getColNum("PATH", rawColList)];
tContent.type = item[MvcApplication.getColNum("TYPE", rawColList)];
tContent.size = item[MvcApplication.getColNum("SIZE", rawColList)];
tContent.modified = item[MvcApplication.getColNum("MODIFIED", rawColList)];
fContentList.Add(tContent);
}
return fContentList;
}
4
Deepak Pote On

you can use "API v1 (Core API)" for : A way to get folder contents for a FileOpen dialog box. A way to read the selected file. Optional: a FileOpen dialog that does all the work to show the files and select one.

take simple example : Get list of files and folders from your dropbox account

      //get the files from dropbox account and add it to listbox

   private void GetFiles()
    {
        OAuthUtility.GetAsync
        (
        "https://api.dropboxapi.com/1/metadata/auto/",
            new HttpParameterCollection
            {
               { "path", this.CurrentPath },
               { "access_token", Properties.Settings.Default.AccessToken }
            },
            callback : GetFiles_Results
        );
    }


  private void GetFiles_Results(RequestResult result)
    {
        if(this.InvokeRequired)
        { 
        this.Invoke(new Action<RequestResult>(GetFiles_Results), result);
        return;
        }

        if (result.StatusCode == 200) //200 OK- Success Codes
        {
            listBox1.Items.Clear();

            listBox1.DisplayMember = "path";

            foreach (UniValue file in result["contents"])
            {
                listBox1.Items.Add(file);

            }

            if(this.CurrentPath != "/")
            {
                listBox1.Items.Insert(0,UniValue.ParseJson("{path: '..'}"));
            }
        }
        else
        {
            MessageBox.Show("Failed to add file to listbox");
        }
    }