Home > DeveloperSection > Articles > Client Object Model in SharePoint 2010

Client Object Model in SharePoint 2010


SharePoint SharePoint 
Ratings:
0 Comment(s)
 4924  View(s)
Rate this:

Client Object Model in SharePoint 2010

In SharePoint 2010 there are a number of object models that can be used by developers to access the server. The Client Object Model (Client OM) is a unified model which uses the same or similar programming concepts as the Server Object Model (Server OM). The Client OM can be accessed via web services, via a client (JavaScript) API, via .NET Managed Applications (using the .NET CLR) and via REST.

Client Object Model is introduced in SharePoint Foundation 2010, and does not require SharePoint Server 2010 to be installed. This is a new object model introduced in SharePoint 2010 which is aimed at making things easier for the developer when developing client-side applications for SharePoint 2010.

Let’s we take a look how to create a client side application using Client Object Model through C# programming language in .NET:

  • Go to Visual Studio 2010.
  • Go to File à New à Project.
  • Select Windows Application and apply the following settings to your project:
    Target Framework: .NET 3.5
     Build output: AnyCpu (or x64)
  • Click Add.

Client Object Model in SharePoint 2010

Client Object Model in SharePoint 2010

Next, we need to add references to the Client Object Model in order to be able to work with the client-side APIs from our Windows Application.

Right click the “References” node and choose “Add Reference”  

Client Object Model in SharePoint 2010

·         Choose Browse:

·         Go to the following location: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI.

·         Select these two files:

Microsoft.SharePoint.Client.dll

Microsoft.SharePoint.Client.Runtime.dll

Client Object Model in SharePoint 2010

Add the following controls in your Windows Application Form:

·         A new ListBox control

·         A new Button control

Client Object Model in SharePoint 2010

After adding controls add the following code in the Form1.cs file:

using System;

using System.Text;

using System.Windows.Forms;

using SharePoint = Microsoft.SharePoint.Client;

 

namespace SampleApplication

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void btnDispList_Click(object sender, EventArgs e)

        {

            listBox1.Items.Clear();

            using (SharePoint.ClientContext objClientContext = new
                                       SharePoint.ClientContext("http://rohit:34143/"))

            {

                var objWeb = objClientContext.Web;

                objClientContext.Load(objWeb);

                objClientContext.Load(objWeb.Lists);

                objClientContext.ExecuteQuery();

                foreach (SharePoint.List objlist in objWeb.Lists)

                {

                    listBox1.Items.Add(objlist.Title);

                }

            }

        }

    }

}

When you run this application and click on button (Display List) it will look something like this

Client Object Model in SharePoint 2010 Thanks for reading this article. I think this will help you a lot when you create your first Client Object Model application to access SharePoint server in C#.


Don't want to miss updates? Please click the below button!

Follow MindStick