WPF Client Interface for SharePoint 2010 Server object
Posted by: Mahesh Sabnis
in Category SharePoint
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
In this article, I am targeting the SharePoint 2010 List Object. Shown below is the object model for the List:
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:
Step 4: In the MainPage.xaml.cs, use the SharePoint assembly as shown below:
Step 5: In the Click event of the ‘Save List’ button, add the following code:
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
This article has been editorially reviewed by Suprotim Agarwal.
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!