Reaching a list from silverlight to sharepoint 2010

Although I have tried everything ,almost every code to get the contents of a list in sharepoint 2010 ,Why am I not able to get the files... below is my code:

===================================================================
            ClientContext ctx = new ClientContext("http://sharepoint-one");
             Site site = ctx.Site;
             Web web = site.RootWeb;
             ctx.Load(web);

             ListCollection lists = web.Lists;
             ctx.Load(lists);

             List taskList = lists.GetByTitle("Shared Documents");
             ctx.Load(taskList);

             CamlQuery query =CamlQuery.CreateAllItemsQuery();

             ListItemCollection listItems = taskList.GetItems(query);
             ctx.Load(listItems);

             ctx.ExecuteQuery();
================================================================================

I have a silverlight application this needs to get into a list in sharepoint and get the files inside... but somehow the code above gives the exception CollectionNotInitializedException in the first line even though the exception i can continue with F10 in debug mode but then it gives error in executequery saying that  :

The method or property that is called may block the UI thread and it is not allowed. Please use background thread to invoke the method or property, for example, using System.Threading.ThreadPool.QueueUserWorkItem method to invoke the method or property.


if I use ExecuteQueryAsync(Onsuccess,Onfailure); then it somehow does not go to onsuccess  or onfailure methods and continues like nothing happens and i cannot get list specific information...

like the count of the items inside the list with

             int count = 0;

             foreach (ListItem a in listItems)
             {
                 count++;
             }

when I try to get info about the list with above code I get the error msg below...

The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
fatihdiAsked:
Who is Participating?
 
quihongConnect With a Mentor Commented:
Here is some code from a workshop I took on SP2010 and Client Object Model. Hopefully it will help you.

using ClientOM = Microsoft.SharePoint.Client;

 using (ClientOM.ClientContext ctx = new ClientOM.ClientContext(textBox1.Text))
    {
        ClientOM.Web site = ctx.Web;
        ctx.Load(site);
        ctx.Load(site.Lists);
        ctx.Load(site,
            x => x.Lists.Where(l => l.Title != null));
        ctx.ExecuteQuery();
        foreach (ClientOM.List list in site.Lists)
        {
            listBox1.Items.Add(list.Title);
        }
    }
0
 
quihongCommented:
Are you using the Client Object Model? For Silverlight I believe you need to.
0
 
fatihdiAuthor Commented:
yes i am using client object model thats right
0
 
vic_muleCommented:
Thanks a lot quihong. That resolved the issue for me. Looks like you have to load the object and that did the trick for me.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.