1

I am running a very simple Console Application to test SharePoint 2010 client object model. Here is the code

using System;
using Microsoft.SharePoint.Client;

class Program
{
    static void Main()
    {
        ClientContext clientContext =
            new ClientContext("http://myserver.contoso.com");
        List list = clientContext.Web.Lists
            .GetByTitle("Announcements");
        clientContext.Load(list);
        clientContext.ExecuteQuery();
        Console.WriteLine("List Title: {0}", list.Title);
        CamlQuery camlQuery = new CamlQuery();
        camlQuery.ViewXml = "<View/>";
        ListItemCollection listItems = list.GetItems(camlQuery);
        clientContext.Load(listItems);
        clientContext.ExecuteQuery();
        foreach (ListItem listItem in listItems)
            Console.WriteLine("Id: {0} Title: {1}",
                oListItem.Id, listItem["Title"]);
    }
}

The problem is everything works fine. It just that the rows are not retrieved from any list or library. The collection is always empty even if there is data in actual list.

Any ideas ?

This example is exact copy paste from MSDN

  • Does the "List Title: {0}" print anything? – Russell Jan 2 '12 at 22:23
  • No, it does not go into loop. I found it, it was due to insufficient permissions. – Madhur Ahuja Jan 3 '12 at 5:07
  • Really strange!! I can't find any mistake in code...it should work. Hope you ran Visual Studio with Run As Admin attribute..? – NICK Jan 3 '12 at 8:58
2

Strangely, this was caused by insufficient permissions.

  • 1
    Can you shed some light on the permissions you needed? Having the same issue with only some users getting zero results, elevated users getting all results. – Michael K Oct 5 '18 at 15:50
0

It's in AppManifest.xml. Under the Permission tab, you can set Scope for List, Search, Site Collection, etc. Once you select the scope you provide a Permission (e.g. FullControl).

Related question here

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.