Accessing SharePoint Lists by Using WCF Data Services in Windows 8 app
This walkthrough shows how to create a Windows 8 app that displays SharePoint Announcement, Tasks, Calendar and Documents lists information by using the ListData.svc WCF data service .
You can download the complete Visual Studio project for this tutorial from CodePlex. Download the source code. You can also view the source code on the this page.

Prerequisites
- Download the Windows 8 Developer tools and SDK
- WCF Data Services Tools for Windows Store Apps
- Visual Studio 2012 / Windows 8 / SharePoint 2010 or SharePoint 2013
Creating a Windows Store Application
- Launch Visual Studio 2012 and select File > New Project.
- Create a new Visual C# project using the Grid Application template.
- Add a Service Reference. In Solution Explorer, right-click the name of the project and then click Add Service Reference.
- In the Address box, type the URL to the target site and append /_vti_bin/ListData.svc.
- Change the default name in the Namespace box from ServiceReference1 to something more appropriate, such as SharePointService.
- Click OK to create proxy classes, including a data context and entity classes for the lists that you want to access.
Creating the DataSource for the Grid
- Right mouse click on the "DataModel" folder and add a new class and call the new class SharePointDataSource.cs
- Add the following namespace references. using SharePointLists.SharePointService;
using System.Data.Services.Client;
using System.Net;
using System.Text.RegularExpressions;
using Windows.UI.Xaml.Media;
using System.Collections.ObjectModel;
using Windows.UI.Xaml.Media.Imaging;
using System.Collections.Specialized; - Add the following variable declarations at the top of the class.
private static SharePointDataSource _SharePointDataSource = new SharePointDataSource()
private DataServiceCollection<AnnouncementsItem> announcements = new DataServiceCollection<AnnouncementsItem>();
private DataServiceCollection<SharedDocumentsItem> sharedDocuments = new DataServiceCollection<SharedDocumentsItem>();
private DataServiceCollection<CalendarItem> calendar = new DataServiceCollection<CalendarItem>();
private DataServiceCollection<TasksItem> tasks = new DataServiceCollection<TasksItem>();
private TeamSiteDataContext context;
private ObservableCollection<SharePointDataGroup> _allGroups = new ObservableCollection<SharePointDataGroup>(); - Replace the constructor with the following:
public SharePointDataSource()
{
context = new TeamSiteDataContext(new Uri("http:///_vti_bin/ListData.svc" ));
NetworkCredential credentials = new NetworkCredential();
context.UseDefaultCredentials = false;
context.Credentials = new NetworkCredential("username", "password", "domain");
announcements = new DataServiceCollection<AnnouncementsItem>();
announcements.LoadAsync(context.Announcements);
announcements.LoadCompleted += new EventHandler<LoadCompletedEventArgs>(announcements_LoadCompleted);
tasks = new DataServiceCollection<TasksItem>();
tasks.LoadAsync(context.Tasks);
tasks.LoadCompleted += new EventHandler<LoadCompletedEventArgs>(tasks_LoadCompleted);
calendar = new DataServiceCollection<CalendarItem>();
calendar.LoadAsync(context.Calendar);
calendar.LoadCompleted += new EventHandler<LoadCompletedEventArgs>(calendar_LoadCompleted);
sharedDocuments = new DataServiceCollection<SharedDocumentsItem>();
sharedDocuments.LoadAsync(context.SharedDocuments);
sharedDocuments.LoadCompleted += new EventHandler<LoadCompletedEventArgs>(sharedDocuments_LoadCompleted);
} - Add the following Load completed procedures for each list:void announcements_LoadCompleted(object sender, LoadCompletedEventArgs e)
void sharedDocuments_LoadCompleted(object sender, LoadCompletedEventArgs e)
void tasks_LoadCompleted(object sender, LoadCompletedEventArgs e)
void calendar_LoadCompleted(object sender, LoadCompletedEventArgs e)
- Download or view the complete SharePointDataSource.cs here and be sure to replace the "Servername", "username", "password" and "domain" with the server and credentials of your server that's running SharePoint.
- Make sure to replace the DataSource on you project. Find all data:SampleDataSource in the xaml files, and replace it with data:SharePointDataSource. And in the xaml.cs files replace all SampleDataSource with SharePointDataSource.
- Run your app :)