One C # API to access Dropbox, iCloud, SkyDrive, etc.?

I am looking for a way to read files from all the different cloud storage systems out there without writing code for each specific API. Is there a way to do this? We need quite simply:

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

thanks - dave

+3


source to share


2 answers


There is a solution to this problem. point.io has a public api that gives brokers access to cloud and corporate storage via a restful api. This is mainly the functionality you are looking for. The api allows developers to view various storage providers as types and does all the heavy lifting for your application.

They have a github repo with c # ccc code examples



Here is some simple C # code that calls the 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;
}

      

+2


source


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

take a simple example: get a 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");
        }
    }

      

-1


source







All Articles