WPF Interface for SharePoint 2010 Client Object Model

Posted by: Mahesh Sabnis , on 9/13/2011, in Category SharePoint
Views: 111515
Abstract: SharePoint 2010 has provided both the Server Object and Client Object model using which a developer can use a client interface like WinForm or WPF and interact with SharePoint 2010 Web Applications, as well as work with SharePoint Objects. In this article, I have demonstrated working with the Client-Object model.

SharePoint 2010 has provided both the Server Object and Client Object model using which a developer can use a client interface like WinForm or WPF and interact with SharePoint 2010 Web Applications, as well as work with SharePoint Objects. SharePoint 2010 has also provided Web Services and WCF services using which any client UI application can interact with it.

A couple of days ago, I had published an article on
WPF Client Interface for SharePoint 2010 Server-Object Model. In this article, I have demonstrated working with the Client-Object model and here’s what we will be looking at:

silverlight client object model

To use client object model, SharePoint 2010 has provided the following assembly references:

 

  • Microsoft.SharePoint.Client.dll
  • Microsoft.SharePoint.Client.Runtime.dll

You can find these references from the following path:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI

In the below article I have used the following class(es) in Microsoft.SharePoint.Client.dll:

Microsoft.SharePoint.Client.dll

In this article, I am assuming that you have some basic understanding of SharePoint 2010 and can create a Web Site collection and can create a List using SharePoint 2010 administration. For this article I have created the following SalesInfo List.

sharepoint list

Creating WPF Client to Load the SharePoint List Information and create a new List Entry

In the steps below, we will create a WPF client application to interact with SharePoint Web Site and work with the List.

Step 1: Open VS2010 and create a WPF application, name it as ‘WPF_SPS_ClientObjectModel’. In this project, add the SharePoint 2010 client Object Model assemblies mentioned in the beginning of this article.

Step 2: In MainWindow.Xaml, add the following XAML:

wpf-sharepoint-client-object

Step 3: Open MainWindow.xaml.cs and add the following namespaces:

image

Step 4: Define the following variable and objects on the MainWindow class level:

image

Step 5: Define code in the Windows Loaded event. This will establish the ClientContext and establish connection to the Web Site, as shown below:

client context

Step 6: Write the following code in the click event of the ‘Load Sales Details’ button. This code gets the ‘SalesInfoList’ List and reads data from it. The data is displayed in the DataGrid. In this code I have written comments on each line for better understanding. The code is as below:

load-sales-info

Step 7: Run the application and click on the ‘Load Sales Details’ button, the following result will be displayed:

sharepoint demo

Step 8: Stop the application and add the following code in ‘Save’ button click event:

add-item-sharepoint-list
The above code adds a new Sales Record in the List using the Client Object Model. Please read comments on the code.

Step 10: Now run the application and enter values in the text box and click on the ‘Save’ button

sharepoint demo
Click on the OK button on the Message Box and then Click on the ‘Load Sales Data’ button - the DataGrid should show the new added entry:
sharepoint demo

You can also verify the List Data on the Web Site by sending request to the Web Site Url as shown below:

clip_image006

The above Orange Marked rectangle represents the newly added entry.

Conclusion: Using the SharePoint Client object model, developers can work with the SharePoint Web Application remotely.

The entire source code of this article can be downloaded
over here

This article has been editorially reviewed by Suprotim Agarwal.

Absolutely Awesome Book on C# and .NET

C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.

We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).

Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.

Click here to Explore the Table of Contents or Download Sample Chapters!

What Others Are Reading!
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+

Author
Mahesh Sabnis is a DotNetCurry author and a Microsoft MVP having over two decades of experience in IT education and development. He is a Microsoft Certified Trainer (MCT) since 2005 and has conducted various Corporate Training programs for .NET Technologies (all versions), and Front-end technologies like Angular and React. Follow him on twitter @maheshdotnet or connect with him on LinkedIn


Page copy protected against web site content infringement 	by Copyscape




Feedback - Leave us some adulation, criticism and everything in between!
Comment posted by Sachin Nimbalkar on Wednesday, September 14, 2011 1:09 AM
This article helps me understanding integration between SharePoint2010 and Client Application. Can you also something about Integration between the Silver-light and SharePoint 2010.
Comment posted by Sachin Nimbalkar on Wednesday, September 14, 2011 1:10 AM
This article helps me understanding integration between SharePoint2010 and Client Application. Can you also something about Integration between the Silver-light and SharePoint 2010.
Comment posted by Mahesh Sabnis on Wednesday, September 14, 2011 1:56 AM
Hi Sachin,
Thanks a lot.
I am currently working on the same. Probably you will find the integration between SL and SPS 2010 soon on the site.
Thanks
Regards
MAhesh Sabnis
Comment posted by somesh Batra on Saturday, November 26, 2011 5:06 AM
This is one of the best article so far, I  have read online. No crap, just useful information. Very well presented. I had found another good collection of SharePoint interview question and answer over internet. For more details please check out this link...
http://www.mindstick.com/Interview/1186/what%20is%20sharepoint%20client%20object%20model
Comment posted by Sruthi on Wednesday, December 7, 2011 3:46 AM
WPF Interface for SharePoint 2010 Client Object Model

Hi
Mahesh

WPF Interface for SharePoint 2010 Client Object Model

i have seen this blog regarding the requirement of my is same i have use the same code but if i am updating the things in the list i am unable to do that can u please give me the solutions for that

Regards
Sruthi
Comment posted by Lee on Thursday, June 28, 2012 10:08 AM
Thanks...great article and finally a walkthrough that actually works!!! :)
Comment posted by gfhfgh on Monday, August 27, 2012 7:53 AM
dfgdfgf
dfgdfgdfg
Comment posted by almas on Tuesday, October 16, 2012 2:29 AM
i just want to know that what is difference between both article given by u. Main question is that what is the use of client object model as compare to other article "WPF Client Interface for SharePoint 2010 Server object"
Comment posted by jamila on Wednesday, November 21, 2012 3:20 AM
Very useful article thanks a lot
I have some question , bref how can i have access to Documents in a library which is deployed in a remote Sharepoint 2010 server
Comment posted by Sathishkumar Ganesan on Monday, February 4, 2013 11:59 PM
Hi Madesh,

Its really very good articles for which is you have posted here. thank you. i got chance to taken the training from you for the silver light in Chennai two years back. very nice experience.
thanks once again.