CHAPTER 10 Client-Side Development with Silverlight


Advertisement

One particularly nice feature of SharePoint Online is the capability to develop and  deploy Silverlight client applications within it. Silverlight  allows you to create rich Internet applications (RIAs) within SharePoint and  can significantly enhance the user experience of your site. You can also access and  work with SharePoint data within your Silverlight application by using the SharePoint client object model or Representational State Transfer (REST) services (see Chapter 9). Among other benefits, using  Silverlight can improve the performance of your site because Silverlight  code  runs on the client rather than on the server.


The topic  of Silverlight integration with SharePoint is pretty broad and  is impossible to cover in just one chapter, so we had  to be fairly selective in what  we chose to include here. For example, because there are already a lot of great  resources available for learning Silverlight, we chose not to cover that topic here. We assume if you’re reading this, you at least have a passing familiarity with Silverlight development (XAML, data binding, out-of-browser applications, .xap files, and  so on). However, if you need a primer on Silverlight  development, a great  place  to start is http://www.silverlight.net.


In this chapter, we’ll cover the following topics, all of which relate specifically to developing Silverlight  applications for SharePoint Online:

 

•   Preparing Your Development Environment for Silverlight

 

•   Building a Silverlight  Application with the Client Object Model

 

•   Deploying Silverlight  Applications to SharePoint Online

 

•   Hosting Silverlight Applications in SharePoint Online

 

Preparing Your Development Environment for Silverlight

First, it’s important to understand that although server-side code  for SharePoint Online cannot exceed version 3.5 of the .NET Framework, Silverlight has no such restriction. Silverlight 4 and  5 will both work just fine with SharePoint Online. Because the most recent release of Silverlight  at the time  of this writing is Silverlight  5, we’ll be using  that version throughout the rest of this chapter.

 

Getting the Necessary Tools and  Software

If you haven’t already done so, the first thing you need to do is install Service Pack 1 for Visual Studio 2010 because it’s required by the Silverlight 5 Tools for Visual Studio. You can download Service Pack 1 at http://bit.ly/khSjYE.


Next, you need to install the Silverlight 5 Tools for Visual Studio SP1, which can be downloaded at http://bit.ly/rTuFvc. This package installs the Silverlight 5 SDK and  runtime so you can use them for development.


Optionally, you can also download and  install the Silverlight 5 Toolkit, which is available on CodePlex at http://silverlight.codeplex.com. Strictly speaking, the toolkit isn’t required for Silverlight development, but it provides additional controls and  examples you will likely find useful. DataForm and BusyIndicator, for example, are two controls that both come from this toolkit and  are used in a lot of Silverlight  applications.


Expression Blend is another optional tool you may want  to consider using for Silverlight development. It’s an integrated development environment (IDE) like Visual Studio, but is oriented toward designers rather than developers. Although Visual Studio 2010 now has a fairly decent XAML designer baked in for Silverlight, Expression Blend is still a far superior tool for developing sophisticated user interfaces (UIs), especially when themes or animations are involved. Expression Blend 4 is the current version at the time  of this writing and  is designed to work with Silverlight 4 projects. However, there’s a preview version of Expression Blend 5 available for working with Silverlight  5 projects. Visit http://www.microsoft.com/expression for more details.

 

Note  Unless you’re doing only Silverlight development (and someone else is doing the SharePoint work), your development environment also needs to be set up for SharePoint Online, as described in Chapter 3.

 

Creating and  Linking Your Projects

If you can get away with it, the easiest way to structure your projects is to place  your Silverlight  and SharePoint projects within a single solution in Visual Studio. Among other benefits, this structure lets you link the projects together. Linking the projects ensures the Silverlight  project is built  when the SharePoint project is built and  also ensures the output (.xap file) of the Silverlight  project is automatically added to the SharePoint project for deployment (via a module element in a feature). That way, you don’t  have to worry about keeping everything synchronized.


Note that if you plan  to deploy the Silverlight application manually and  have no other need for a SharePoint project in Visual Studio, simply  creating the Silverlight  project alone should be sufficient (and there’s also no need to link it with any other projects in that case).

 

Creating a SharePoint Project

 

First, we’ll walk through creating a SharePoint project in Visual Studio. You can skip this step  if you already have one or have no need for a SharePoint project in your solution.

 

1.    Open the File menu in Visual Studio and  choose New † Project.

 

2.    On the New Project dialog,  expand the SharePoint node on the left and  choose 2010. Select the Empty SharePoint Project template, give it a name, and  click OK. See Figure  10-1 for an illustration of this step.

 

 

Figure 10-1. Creating  a new SharePoint project in Visual Studio 2010

 

Tip  If you’re creating a new solution that will house both your SharePoint and Silverlight projects, we recommend checking the Create directory for solution box, as shown in Figure 10-1. This will create a parent folder (which we’ve named “Chapter 10”) for the solution, and your two projects will both be subfolders.

 

3.    After clicking OK to create the project, Visual Studio will display the SharePoint Customization Wizard, as depicted in Figure  10-2. Enter the URL of the site where you’ll be testing/debugging your code,  and  select  the Deploy as sandboxed solution deployment option (recall from Chapter 7 that farm solutions—the other choice–are not allowed in SharePoint Online even though Visual Studio doesn’t specifically call that out).

 

4.    Click Finish on the SharePoint Customization Wizard to finish  creating the project.

 

 

Figure 10-2. SharePoint Customization Wizard in Visual Studio

 

Creating a Silverlight Project

The following steps will guide  you through creating a Silverlight  project in Visual Studio. Steps 2 and  3 are illustrated in Figure  10-3.

 

1.    Open the File menu in Visual Studio, and  choose New † Project.

 

2.    On the New Project dialog,  select  the Silverlight node on the left. Select a Silverlight  project template (normally Silverlight Application) and  give it a name.

 

3.    If you’re adding this project to an existing solution, select  Add to solution from the Solution drop-down near the bottom of the dialog.

 


Advertisement

4.    Click OK to create the project.