How to Build a RSS Reader for Windows Phone 7

9 min read


Microsoft SharePoint 2010 Enterprise Applications on Windows Phone 7

Microsoft SharePoint 2010 Enterprise Applications on Windows Phone 7

Create enterprise-ready websites and applications that access Microsoft SharePoint on Windows Phone 7

        Read more about this book      

(For more resources on Microsoft Sharepoint, see here.)

Security in SharePoint 2010

We begin this article with a discussion on security for a very simple reason: security in SharePoint is tricky. In addition to that one very simple reason, authenticating users against SharePoint from within a Windows Phone 7 client application is even trickier.

In this article, the example RSS reader that we develop will only use anonymous access to the RSS feeds in SharePoint. Setting up anonymous access is very simple and we’ll walk through the steps here.

When writing this article, I came across a lot of errors on my testing server, but not my development server. After a couple of days of unsuccessful web searches and reinstalling different components, I discovered the root of my problem was due to the fact that the SharePoint 2010 Prerequisites install a non-final version of ADO. NET Data Services 1.5. Make sure the final version is installed from Microsoft. More information is available at the following URL:

There are two places where we need to make changes to our SharePoint site to enable anonymous access:

  • Central Administration
  • Site Permissions

Central Administration

Classic mode authentication is more or less just classic Windows authentication using NTLM or Kerberos.

Although Internet Explorer Mobile in Windows Phone 7 can do the NTLM authentication, as we’ve been doing up to now to view SharePoint sites in the browser, the version of Silverlight that is included in Windows Phone 7 cannot currently use this authentication mechanism.

Carry out the following steps to configure Central Administration for anonymous access:

  1. From the Start menu, select All Programs.
  2. Find the folder named Microsoft SharePoint 2010 Products in the list of programs and click on it.
  3. Click on SharePoint 2010 Central Administration.
  4. You need to select the Yes option on the User Account Control dialog that may appear.

At this point, the home page for SharePoint 2010 Central Administration should appear as displayed in the following screenshot:

(Move the mouse over the image to enlarge.)

Next, click on Manage web applications. The page that appears lists out all of the web applications in the SharePoint site. There should be two items listed here, but it is possible there are more. Select the main website by clicking on its name. This main website is usually titled SharePoint – 80. Once selected, the ribbon bar across the top should light up, as all the icons become active. Carry out the following steps to enable anonymous access:

  1. Click on the Authentication Providers icon.
  2. In the Authentication Providers dialog that appears, select the Default link.
  3. The Edit Authentication dialog box will appear. In the third section, down under a heading of Anonymous Access there is a check box listed as Enable anonymous access. Check that box.
  4. Scroll all the way to the bottom of the dialog box and select the Save button.
  5. SharePoint 2010 will process the request. Then, return to the Authentication Providers dialog box and close it.

There is one more section that may need tweaking and if this is a production environment, it should be considered. That section is Anonymous Policy. Click on the icon for it in the ribbon and a dialog box will appear. From here, we can customize the anonymous policy for the site.

  • None – No policy basically leaves the door open for read and write access from anonymous users. This is a good policy to use when anyone who can access the site should also be able to modify the content of the site. This is a good policy for Wiki’s.
  • Deny Write – Has no write access allows the anonymous users to read the site, but they cannot write, update, or delete content. This is a good policy to use for sites that we want to specify particular authenticated accounts write access, but allow everyone the ability to read the content. Some Wiki’s use this policy and a lot of blogs use this policy.
  • Deny All – Has no access selecting this removes all permissions to the anonymous user. Secure content should always use this policy.

Site Permissions

Once we have updated the web application to allow anonymous access, we have to give anonymous users access to the site collection. To do this, we close Central Administration and open our SharePoint site. Once on the site, select Site Permissions from the Site Actions menu.

This will open the Permissions home page. In the ribbon at the top, there is an icon named Anonymous Access. Click on that button and the Anonymous Access dialog will appear, as shown in the following screenshot:

This dialog has three radio buttons to fine tune the access that anonymous users have. The key point to remember here is that although we are really opening up the site for everyone to see, we can break the inherit permissions model on a child page at any time if we need to remove anonymous access.

Now that we have opened up our SharePoint site to anonymous users, we can begin to write applications for Windows Phone 7. In a production environment, we may not have the privilege of opening a SharePoint site this wide, but remember that we are only doing it for demonstration purposes here. We have to walk before we can run. Now, let’s get started on the RSS reader.


Using WebClient to get data from the web

As was stated in the introduction to this article, we are going to build a really simple RSS reader for Windows Phone 7. We are going to keep everything really simple. What that means is that we are going to focus on the pieces of code that actually do something.

This is what we are going to do:

  • Create our base project
  • Add a text block to display the WebClient results
  • Create a WebClient
  • Use the WebClient to request the contents of our SharePoint home page
  • Display the raw HTML that is returned in the text block on the page

First, a quick word about WebClient. WebClient isn’t the most robust method of making requests over a network, but it’s really simple and works for simple cases, such as the one we are working with.

Creating the base project

We can start by creating our base project. This RSS reader will use the Visual Studio Silverlight for Windows Phone Windows Phone Application template. Carry out the following steps to start the project:

  1. Open Visual Studio 2010.
  2. Select File from the main menu and then select New Project….
  3. In the New Project dialog box that appears, select Silverlight for Windows Phone.
  4. Then select Windows Phone Application from the list of templates for Windows Phone.
  5. Give the project a name, for example SimpleRSSReader.
  6. Give the Solution a name, for example Chapter06.
  7. Change the Location as desired and click on the OK button.

At this point, Visual Studio will go off and create the solution and project. When it has finished, MainPage.xaml will appear on the screen in split screen mode, as shown in the following screenshot:

Displaying WebClient results by adding a text block

The first thing we are going to do here is add a text block to the content panel. Add the following code to the Grid that has a name of ContentPanel.

<TextBlock x_Name="webClientResults" />

This creates a text block named webClientResults and puts it in ContentPanel. We could spruce this up a bit by providing a font size, or padding, but we are going to keep this really simple and only show the code needed to get things done.

Save the progress.

Creating a WebClient

Open up the code behind by either clicking on it in the top tab bar, double-clicking the file name in Solution Explorer, or press F7 while in the XAML code.

In the code behind, create a private member variable, outside the constructor, named client of type WebClient and a private member variable, also outside the constructor, named siteUrl of type string. The siteUrl should have a value that is the URL to your SharePoint home page.

private WebClient client = new WebClient();
private string siteUrl = "http://ssps2010/";

These are the variables that we’ll be using in just a minute. The first is the WebClient that makes the requests on the network. The second is the Url for our SharePoint home page. This is the address that the WebClient will use to request a web page.

Requesting the contents of our SharePoint home page

Now that we have a WebClient, let us do something with it. Add the following code to the Main Page constructor:

client.DownloadStringCompleted += new DownloadStringCompletedEventHand
client.DownloadStringAsync(new Uri(siteUrl));

The first line adds a new event handler to the DownloadStringCompleted event. This event handler is called client_DownloadStringCompleted and we will write it shortly. The second line is what starts an asynchronous request to our SharePoint home page to get the HTML content.

Displaying the raw HTML that is returned

Until now, we’ve created a place in the content panel to display our results. We’ve created a couple of variables. We’ve added a new event handler for when the WebClient finishes and we’ve made the web request for our SharePoint home page. Next, we are going to receive the result from the WebClient.

Earlier, when we added a new event handler to the WebClient, we told WebClient that when it finishes downloading the string, it should call our method named client_DownloadStringCompleted. The following is the code for that method:

void client_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e) {
if(e.Error == null) {
webClientResults.Text = e.Result;

First, we check to see if there is an error. To make this as simple as possible, we are not handling the situation where there is an error. We only care if there are no errors. Always check that errors are null. If there is an exception in the WebClient request, the DownloadStringCompletedEventArgs Error property will contain an object of type Exception. These exceptions can range from network connections being down, which is common for cell phones, to invalid URLs.

We then take the result of the web request and put it in the text block we created earlier. Save the progress and press F5 to see the application run on the Windows Phone 7 Emulator.

Microsoft SharePoint 2010 Enterprise Applications on Windows Phone 7

In the preceding screenshot, ApplicationTitle and PageTitle have also been updated. Both of these text blocks are found in the XAML in TitlePanel.

We have successfully used WebClient to read data from the web and display it on the screen. It is still in a raw format though, and it isn’t much of an RSS reader, especially since this page isn’t even RSS. We will get there, but first let’s find some RSS in SharePoint.



Please enter your comment!
Please enter your name here