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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
quihongCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.