Question

I have personal files in My Documents folder in SkyDrive Pro from Office 365.

As I understand, SkyDrive Pro uses SharePoint as backing storage. Can I access those files with SharePoint API (Microsoft.SharePoint.Client.ClientContex)?

I mean SkyDrive Pro from Office 365. For example, if you go to the companyname.sharepoint.com, you will have menu in the right corner: Outlook, Calendar, People, Newsfeed, SkyDrive. And it is different from SkyDrive for consumers. enter image description here

Was it helpful?

Solution

Yes, you can access files and folders information via ClientContext as usual. The only difference is that when constructing ClientContext, you need to use different URL – the one you see when you go to the "SkyDrive" tab (something like https://companyname-my.sharepoint.com/personal/username_companyname_onmicrosoft_com/).

If you want to retrieve this URL programmatically, you can use the following snippet:

 var clientContext = new ClientContext("https://**companyname**-my.sharepoint.com/");
 clientContext.Credentials = new SharePointOnlineCredentials(**userName**, **password**);

 var props = peopleManager.GetMyProperties();

 clientContext.Load(props);            
 clientContext.ExecuteQuery();

 Console.WriteLine(props.PersonalUrl);

OTHER TIPS

http://msdn.microsoft.com/en-us/library/office/dn423226.aspx

    public static void GetSkyDriveFiles(string path, int rowLimit, string sortExpression)
    {
          string queryText = "Path:\""+path+"Documents/*\" IsDocument:1";    
          //string uriTempale = "{0}_api/search/query?querytext='{1}'&rowlimit={2}&sortlist='{3}'";
           var clientContext = new ClientContext(@path)
           {
                  Credentials = "ur credentials";
           }


           cxq.KeywordQuery keywordQuery = new cxq.KeywordQuery(clientContext);
           keywordQuery.QueryText = queryText;
           keywordQuery.RowLimit = rowLimit;
           cxq_ConvertSortExpressionToList(keywordQuery.SortList, sortExpression);
           //keywordQuery.SortList.Add("Write", cxq.SortDirection.Ascending);

           cxq.SearchExecutor searchExecutor = new cxq.SearchExecutor(clientContext);
           ClientResult<cxq.ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
           clientContext.ExecuteQuery();
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top