Tuesday, January 12, 2010

COM (Client Object Model) in SharePoint 2010.

With SharePoint 2010 you can write client Applications based on Microsoft .NET framework and that can access SharePoint Server Content without installing Application on the server that runs  SharePoint Server 2010.    

The SharePoint  client object model lets you write client-side code to work with all the common objects in SharePoint sites.

  1. List
  2. Sites
  3. Web Parts
  4. Document Library

Through the object model, you can add and remove lists, add, update, and delete list items, change documents in document libraries, create sites, manage permissions of items, and add and remove Web Parts from a page.

Lists Add, Remove
List Items Add,Update,Delete
Sites
Create, Manage permission
Web Parts Add, Remove Web Parts from a Page.

SharePoint 2010 Client Object Model consists of two .NET Assembly

  1. Microsoft.SharePoint.Client.dll
  2. Microsoft.SharePoint.Client.Runtime.dll

image

How Client Object Model Works

SharePoint  client object model bundles up API calls into XML and sends it to the server that runs SharePoint Foundation. The server receives this XML request, and makes appropriate calls into the object model (Lists, Web, Site) on the server, collects the responses, forms them into JavaScript Object Notation (JSON), and sends that JSON back to the Calling Application SharePoint client object model. The client object model parses the JSON and presents the results to the application as .NET Framework objects (or ECMAScript objects for ECMAScript).

The Following diagram shows the above Client object Model Method calls.

image

Now i am going to build  Sample  WPF Application. First we need to  add references to two assemblies, Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll. you can find these assemblies on the server and they are located in the following directory %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\ISAPI.

Create New WPF Project and Add SharePoint Client object Model Dll. and Make sure that you set Build option as  Platform target to  Any CPU

image

Now we are going to query all the list from http://win-m2ircoq6iqa:44119/ site.  add the following controls to above Created WPF Application.  ListBox, Button and Text Block.

image

First Create the ClinetContext object to connect the site in SharePoint Server to work with then you need to select the object you wanted to work with here i am selected SharePoint List and then you execute the Query and get the response.

  •  ClientContext object to connect the SharePoint site and work with the SharePoint server
  •  ClientContext.Load() to load the objects you need to work with
  •  ClientContext.ExecuteQuery() to execute the query and get response as COM objects

    image

    Nandri(Thanks)

    SreenivasaRagavan.

  • 1 comment:

    Unknown said...

    Good introduction.
    Here are some posts which I have written.

    Client Object Model: http://praveenbattula.blogspot.com/search/label/Client%20Object%20Model

    All SharePoint 2010: http://praveenbattula.blogspot.com/search/label/SharePoint%202010

    Samples and examples: http://praveenbattula.blogspot.com/2010/04/sharepoint-2010-managed-client-object.html

    thanks
    -Praveen.