Home > Client object model > How to use the client object model with SharePoint2010

How to use the client object model with SharePoint2010

In SharePoint2010, you can use client object model to communicate with SharePoint server. Today, I’d like to show you how to achieve this by using the c# console application. You can download the solution here.

1. Create a Console application in visual studio and add the following references to the project.


2. Insert your code as below

            ClientContext context = new ClientContext("http://demo2010a");
            Web currentWeb = context.Web;
            context.Load(currentWeb, web => web.Title);
            context.ExecuteQuery();
            Console.WriteLine(currentWeb.Title);
            Console.ReadLine();

3. Run your code then you will get the web title displayed as shown below

Note:

If you got the following errors, you need to change your target framework from .Net Framework 4 client profile to .Net Framework 4 as shown below:

Change from

TO

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: