DotNetCurry Logo

WPF Client Interface for SharePoint 2010 Server object

Posted by: Mahesh Sabnis , on 9/2/2011, in Category SharePoint
Views: 93886
Abstract: SharePoint 2010 provides the Server Object model using which a SharePoint WebSite Collection, WebSite, Lists and similar kind of objects can be accessed and programmed in client applications like WinForm, WPF etc. This feature is used by developers who are responsible to make new data entry on the SharePoint portal from their desktop applications.

Can we integrate SharePoint 2010 objects with standard Desktop application created using WPF or WinForm?

SharePoint 2010 provides the Server Object model using which SharePoint WebSite Collection, WebSite, Lists and similar kind of objects can be accessed and programmed in client applications like WinForm, WPF etc. For this article, I am assuming that the readers know how to create a SharePoint List. I have created a simple website where Sales information is stored using the SalesInfo List as shown below:

Note: Make sure you also read SharePoint 2010 Tutorials For Beginners and Intermediate Developers


Sharepoint List
In this article, I am targeting the SharePoint 2010 List Object. Shown below is the object model for the List:

Sharepoint List Object Model
The above object model clearly indicates that to program against the SharePoint ListItem (SPListItem) in the SharePoint, you need to iterate through the SharePoint SiteCollection (SPSite). The SPWeb represents the Web site which contains the SharePoint List (SPList).

 

In the scenario below, I am using the SalesInfo SharePoint List for sales statistics of a product across various regions. This allows various sales persons to collect region wise sale data and update the List developed using the SharePoint technology.

Creating a WPF Desktop client Application

Step 1: Open VS2010 and create a WPF application called ’WPF_SPS_Server_Object’. Make sure that it targets .NET 3.5 frameworks since the SharePoint 2010 object model currently targets .NET 3.5.

Step 2: In this project, add a reference to Microsoft.SharePoint.dll. You can find it on your machine on the following path:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI

Step 3: Design the WPF application as below:

WPF Sharepoint App

Step 4: In the MainPage.xaml.cs, use the SharePoint assembly as shown below:

using Microsoft.SharePoint;

Step 5: In the Click event of the ‘Save List’ button, add the following code:

Sharepoint Object List


The above code works with SalesInfo List in the ‘http://Mahesh-pc/sites/Products’ site collection. Please read comments in the code carefully.

As you can see, the code shown above makes easy use of the SharePoint 2010 object model. Using this feature of SharePoint, a user can update the SharePoint application without physically using/logging into a browser. This feature is used by developers who are responsible to make new data entry on the SharePoint portal from their desktop applications.

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

Recommended Articles
Author
Mahesh Sabnis is a Microsoft MVP having 14 years 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). Follow him on twitter @maheshdotnet


Page copy protected against web site content infringement by Copyscape




Leave us some feedback
comments powered by Disqus
No Comments Found! Click on the 'New Comments' tab to post your comment
Free DNC .NET Magazine