I'm hoping I can list and add folders and files to a specific Office 365 SharePoint site using Office 365 client API. (NOTE - I originally posted this Q to StackOverflow and was recommended to ask here)

I have an ASP.NET MVC application and with the help of the Office SDK for VS 2013 and the Azure Portal I've given the website permission to some office 365 api's like Contacts and Sites (RootSite). I can successfully authenticate for both Contacts and RootSite capabilities, but I cannot find any information about how to get a list of available SharePoint sites or list files and folders of a specific SharePoint directory. Is it not possible with the SharePointClient of the Microsoft.Office365.SharePoint.CoreServices library?

I've tried to get files from the "root" (wherever that is in this SharePoint case) with

//...create Discovery client etc...
var dcr = await discClient.DiscoverCapabilityAsync("RootSite");
var client = new SharePointClient(dcr.ServiceEndpointUri, //... and so on...
var files = await client.Files.ExecuteAsync();  // bombs with file not found

But this ends in an FileNotFound Exception.

  • It would appear that the URL generated by these libraries is incorrect. Rather than posting the request to /_api/v1.0/files it's just posting them to /_api/files. It's correct for the MyFiles bit, but not for RootSite – Matthew Steeples Aug 8 '15 at 15:24

After trying a number of different ways, I've found that using the SharePoint Client Object Model (Microsoft.SharePoint.Client) libraries are the most stable ones to use against Office365 Sharepoint sites and lists. So that's what I did. There are numerous examples of that out there so I'm not posting anything here unless someone wants it - just comment.


OK, some digging around. It would appear that the new Onedrive API is available under v2 on SharePoint Online, so the "classic" API is now on V1. This library doesn't seem to be aware of this and so doesn't append v1.0 for the URL. The following code snippet should sort it for you (as it has for me):

var url = dcr.ServiceEndPointUri;

const string version = "/v1.0";

if (!url.ToString().EndsWith(version))
    url = new Uri(url + version);

SharePointClient myFilesClient = new SharePointClient(url, //etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.