Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
    
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
add comment

2 Answers

up vote 1 down vote accepted

Strangely, this was caused by insufficient permissions.

share|improve this answer
add comment

Really strange!! I can't find any mistake in code...it should work.

Hope you ran Visual Studio with Run As Admin attribute..?

share|improve this answer
    
Its correct now. See my other answer. It was caused due to insufficient permissions. –  Madhur Ahuja Jan 3 '12 at 9:28
    
Thanks for sharing. –  NICK Jan 3 '12 at 10:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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