Fall Conference Wrap-Up – Part 4

My new column is up on Legal IT Professionals. This is the final part of my Fall Conference Wrap Up series. In this part, I take the technologies I described in the first three columns, and try to relate them to real business value.

Simple SharePoint 2010 + Silverlight + Client Object Model Example

NOTE: I updated this post today (Feb 7, 2011) to make the code snippets easier to work with. I tried very hard not to introduce any new typos as I did this, but if you see anything wonky, let me know (if somehthing is not working – think about typos FIRST!)!

This post will take you through a very simple example of using a Silverlight application in SharePoint 2010, using the new SharePoint 2010 Client Object Model. I will also show how to use the new SharePoint 2010 tools in Visual Studio 2010 to package the Silverlight application for deployment. Note that I will not be getting into the details of creating a flashy (no pun intended) UI in Silverlight – i will just create a very simple UI with a list box and a text box.

The Example is broken into 2 parts. The first will describe how to create a SharePoint 2010 solution which will deploy a Silverlight XAP file to SharePoint. The second part will introduce a simple Client Object Model solution in Silverlight.

Part 1 – Creating a SharePoint 2010 Solution to Deploy a Silverlight Application

1) Start with a Team Site in SharePoint 2010 (I am sure any other site type would work just as well).

2) Create a document library to store your Silverlight XAP file (I called mine Silverlight).

3) On the home page of the team site, add a SharePoint Silverlight web part as shown below:

Silverlight Web Part

Next, we will create the Visual Studio 2010 solution.

4) Create a new Visual Studio project, selecting the Empty SharePoint Project template (Visual C# | SharePoint | 2010 | Empty SharePoint Project). Name your solution SharePointSolutionDeployment. This will also add an empty SharePoint project in the solution. Make sure you point to the site you just set up for debugging. In addition, you have the option of creating a Sandbox or Farm solution – in general you should create a Sandbox solution unless you find you really need to do otherwise.

5) Next, add a Silverlight Application project (Visual C# | Silverlight | Silverlight Application) to the solution.  I named mine Simple Silverlight Application.

6) Change the background colour of the layout grid in the MainPage.xaml file. Double click MainPage.xaml to open it in design mode. and change the background colour of the grid to slate gray (or what ever you like – this is just to make it obvious when it shows up in SharePoint).

Now we will add the Module to the SharePointSolutionDeployment project, which will deploy our Silverlight XAP file to SharePoint.

7) Right click the SharePointSolutionDeployment and select Add | New Item…then select Visual C# | SharePoint 2010 | 2010 | Module. Name it Simple Silverlight Application Module

8) In the Solution Explorer, right click the Sample.txt file, and select Delete (note that it is also automatically deleted from the Elements.xml file).

9) Click on the Simple Silverlight Application Module, and observe the Properties display, as shown below:

Module 1

10) Click on the ellipses to edit the Project Output References collection, and click Add:

Module 2

11) Click the dropdown next to Project Name, and select Simple Silverlight Application. Then change the Deployment Type to ElementFile, and click OK:

Module 3

12) Now, open the Elements.xml from your Simple Silverlight Application Module and make the following changes:

13) In the Module element, add the attribute Url=”name of your document library” (use the name of the document library you created in Step 3).

14) Add the following File element inside the Module element:

<File Path="Simple Silverlight Application Module\Simple Silverlight Application.xap"
      URL="Simple Silverlight Application.xap"
      Type="GhostableInLibrary" />

15) Your Element.xml file should now look like:

<?xml version=1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   <Module Name="Simple Silverlight Application Module" Url="Silverlight">
      <File Path="Simple Silverlight Application Module\Simple Silverlight Application.xap"
            URL="Simple Silverlight Application.xap"
            Type="GhostableInLibrary" />


16) You should now be able to build and deploy your solution (under the Build menu).

17) Once you have deployed the solution, check your SharePoint site to verify that the XAP file was deployed to the Silverlight library.

18) Go to your site home page (or the page where you created your Silverlight web part), and configure the Silverlight web part to point to your XAP file. After saving the settings and saving the page, your Silverlight web part should look something like below (note that the rectangle is slate gray, as we set in step 3):

Part 1 Complete

Part 2 – Using the Client Object Model in the Simple Silverlight Application

In this step, we will modify the Simple Silverlight Application to use the SharePoint 2010 Client Object Model to access information regarding the lists on the site.

19) In the Simple Silverlight Application, add references to Microsoft.SharePoint.Client.Silverlight and Microsoft.SharePoint.Client.Silverlight.Runtime. You will have to browse to find these in the Add Reference dialog. They are located at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin

20) Right-click App.xaml and select View Code.

21) Add the following using statements:

using Microsoft.SharePoint.Client;
using System.Threading;


22) Next add the following statement to the start of the Application_Startup method:

private void Application_Startup(object sender, StartupEventArgs e)
      ApplicationContext.Init(e.InitParams, SynchronizationContext.Current);
      this.RootVisual = new MainPage();


23) Now modify the MainPage.xaml design, adding a List Box and a Text Box as shown below. The List Box will be used to display a list of the lists on the site, and the Text Box will display some details regarding the list selected in the List Box.

<Grid x:Name="LayoutRoot" Background="SlateGray">
   <StackPanel Orientation="Horizontal" >
      <ListBox Name="lbLists" Width="300" Height="400" ScrollViewer.VerticalScrollBarVisibility="Auto" Margin="20,20,20,20" />
      <TextBox Name="txtDetails" Width="200" Height="400" TextWrapping="Wrap" />

24) Right click MainPage.xaml and select View Code. the following using statement to MainPage.xaml.cs:

using Microsoft.SharePoint.Client;

25) Add two member variables as shown below:

private Microsoft.SharePoint.Client.Web _web;
private Microsoft.SharePoint.Client.List _list;

26) Add the following code to the MainPage constructor, below the InitializeComponent() call. Note the call to ExecuteQueryAsync – as this is Silverlight, the queries back tot he server need to be asynchronous.

ClientContext context = new ClientContext(ApplicationContext.Current.Url);

_web = context.Web;


context.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded), new ClientRequestFailedEventHandler(OnRequestFailed));

27) Next, add the two callback routines from ExecuteQueryAsync, as shown below. In OnRequestSucceeded, the call to FillList is called on a separate thread. The OnRequestFailed method is just a stub.

private void OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args)
{ // this is not called on the UI thread

private void OnRequestFailed(Object sender, ClientRequestFailedEventArgs args)

28) Now, implement the FillList method:

private void FillList()
   lbLists.ItemsSource = _web.Lists;
   lbLists.DisplayMemberPath = "Title";

29) Build and deploy the solution. Refresh your page with the Silverlight web part. The List Box should now display a list of the Lists on your site, as shown below:


30) Next, we will add an event handler for the List Box selection changed, and to then retrieve the details for the selected list.

31) In the design view for MainPage.xaml, double click the list box to create a handler for the selection changed event. Add the following code to the event handler (again note the asynchronous call):

private void lbLists_SelectionChanged(object sender, SelectionChangedEventArgs e)
   using (ClientContext context = new ClientContext(ApplicationContext.Current.Url))
      _list = context.Web.Lists.GetByTitle(((Microsoft.SharePoint.Client.List)lbLists.SelectedItem).Title);
      context.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnListDetailsRequestSucceeded), null);

32) Add the callback routine for the asynchronous query:

private void OnListDetailsRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args)
{ // this is not called on the UI thread

33) Finally, add the routine to display the list details in the Text Box:

private void ShowListDetails()
   string infoAboutList =
      string.Format("List Details:" + Environment.NewLine +
                         "Title: {0}" +
                         "Description: {1}" +
                         "Item Count: {2}" +
                         "Base Template: {3}" +
                         "Base Type: {4}" +
                         "Content Types Enabled?: {5}" +
                         "Hidden?: {6}",
                         _list.Title + Environment.NewLine,
                         _list.Description + Environment.NewLine,
                         _list.ItemCount + Environment.NewLine,
                         _list.BaseTemplate + Environment.NewLine,
                         _list.BaseType + Environment.NewLine,
                         _list.ContentTypesEnabled + Environment.NewLine,
                         _list.Hidden + Environment.NewLine);

   txtDetails.Text = infoAboutList;

34) Build and deploy the solution. Refresh your page with the Silverlight web part. As before, the List Box should now display a list of the Lists on your site. Select one of the lists, and the details for the list should be displayed in the Text Box, as shown below:

List Details

This has been a very simple introduction to creating and deploying a Silverlight application into SharePoint 2010, and then using the SharePoint 2010 Client Object Model to access list information and display it in Silverlight. This could be extended to query more information on the Lists, or information on other collections on the site, such as Content Types, or Workflow Templates. The Silverlight UI could also obviously be enhanced as well.

SharePoint Conference 09 Wrapup

It had been my intention to write daily blog posts from SPC09, but honestly there was just too much going, and I was tweeting all day anyway. I thought I would, however, post a summary of the things I saw and learned at the conference (well, the SharePoint things, not the “people acting silly” things 🙂 ). It was a great conference, well organized, and with lots of information – too much information actually, so much that I could not see all the sessions I wanted to and will have to wait for the videos to be posted.

There is a lot of new stuff coming in SharePoint 2010, and a lot of improvements to existing features. Before I get into my thoughts on the conference and SharePoint 2010 in general, I would like to recommend looking at this post. Tony Byrne makes some good points. For me, it can all be condensed down into one statement: No matter what the hype, no matter what fancy new features are there, always, ALWAYS, keep business needs front of mind – upgrade when there is a clear business reason, and not before. All of the features in the world will not help you if you do not know what you are building and why.

So, on to the good stuff! There are many things I saw at the conference which really make me excited about SharePoint 2010. The things that caught my interest can be broken down into the following groups:

  • General SharePoint features
  • Service Architecture
  • Office services
  • Development support and tools

General Features

I am not going to dwell too much on the general SharePoint features, as I am sure there will be lots of articles covering them. Obviously there are considerable user interface enhancements (though the design experts out there will no doubt crap on the overall UI). The ribbon interface is pretty impressive for things like editing pages, working with lists, and similar activities. I am not sure how well it applies in a more generic “web” world, and how it can be made to be non-intrusive in a highly customized deployment.

It is also nice to see a considerable amount of AJAX-like behaviour in the UI, thus greatly reducing the number of post backs and screen refreshes. This includes the new dialog framework – many of the actions which previously sent the user to a second page to collect information, and back again when the action was completed, are now done through layered dialogs (which are also customizable for consistency with your desired look and feel).

There have also been significant improvements to the capacity and scalability of SharePoint lists and document libraries.

Finally, it is nice to see SharePoint moving towards compliance with standards such as WCAG, XHTML, and CMIS.

Services Application Architecture

A major change in SharePoint 2010 is architectural – the introduction of the  Service Application Architecture. This is a replacement for the Shared Service Providers (SSPs) in SharePoint 2007. SSPs hosted such things as the User Profile Service, Search Services, and BDC Services. There were a number of deployment, scaling and manageability issues with SSPS, however.

Service Applications are a far more flexible approach. A Service Application can consist of a package of assemblies, databases, and other components which are deployed to a SharePoint App Server. The service is exposed via a proxy deployed to the WFE. This proxy knows how to talk to a custom WCF service on the App Server. The client (for example a Web Part) talk calls the proxy in order to consume the Service Application, without having to know where the Application Service is deployed – on the same farm or even another farm. The architecture also has built in round-robin load balancing.

Office Services

Among the services deployed in SharePoint 2010 are various office services:

  • Improved Excel Services
  • Improved InfoPath Forms Services
  • Visio Services
  • Access Services

I know there are some great improvements in Excel and Excel Services from the keynote. Excel rendering is improved, as in the interaction experience. Additionally, Excel Services now exposes REST interfaces, making it easier to consume server-based calculations and charts from other pages or web applications.

Something that specifically caught my interest is PowerPivot – which allows Excel to work with huge datasets in an effective way (the keynote showed it working with 100+ million rows – but that of course was a demo). I did not get a chance to go to the PowerPoint sessions, but will definitely have a look at the recordings when they are available. In the meantime, have a look here.

Something new which has been added in SharePoint 2010 are Visio Services allowing for the rendering of Visio diagrams in the browser, with interactivity and data binding. The Visio diagrams are rendered in a SharePoint web part using Silverlight technology. I already have a few ideas for how this could be applied to projects on which I am working.

Also added are SharePoint Access Services. This allows the publication of Access Solutions to a SharePoint where they can be centrally managed, and provides multiuser access and distribution difficult to achieve with an Access desktop solution.

There are a lot of improvements for developers in SharePoint 2010 and Visual Studio 2010.  So much so that I am going to do a completely separate post to cover them. To summarize:

  • Many new and improved templates in VS 2010
  • Visual designers in VS2010
  • Support for Features and Packaging in VS2010
  • Improved APIs (way too much to get into here)
  • Developer Dashboard view
  • Development support on 64-bit Vista/Windows 7
  • Improved tools in SharePoint Designer

I will be posting another write up later today specifically focused on the development improvements.

The Microsoft SharePoint Team Blog has a post summarizing these and many other features I have not gotten into here.

What’s Wrong with SharePoint?

So, I am watching Twitter updates go by (as I always do, even on a Saturday night), including my search that shows me all the tweets with “sharepoint” in them. As anyone knows who watches any amount of SharePoint commentary go by, there is a fairly constant flow of comments of the “SharePoint sucks” variety.

So this evening this led me to ask the question “What is wrong with SharePoint?” No, I do not mean I want a list of every nit picking, annoying little defect – every platform has defects and annoyances. I also do not want to know why SharePoint is note good for everything – no platform is good for everything. I also do not give a crap if your opinion is “it comes from Microsoft therefore it MUST suck” – it that is as deep as your analysis can go, well, you’re a moron.

What I want to see from SOMEONE is an intelligent, well thought out description of why SharePoint sucks. Why is it a bad choice for anything? Why should you perform an exorcism on all servers running any version of SharePoint?

I did a web search (notice I did not say “google” – contrary to popular usage, google is not a verb) for “what is wrong with SharePoint?” The only relevant results I found on either Google or Bing were written in 2005 or before, and hence are not particularly relevant at this point. For example, the post Five Things Wrong with SharePoint from back in 2005 tries to talk about what is actually wrong  with SharePoint. Even though I disagree with a lot of what it says, I will not refute it since it is so old.

So – if SharePoint is so bad…if all the otherwise intelligent people implementing solutions over SharePoint are wrong – where the heck are the statements as to what is wrong with it. So tell me – WHAT IS WRONG WITH SHAREPOINT? I really want to know, and to share it with others.