search blog
most popular
MCP MCTS MCT MVP

How To: SharePoint and Silverlight 2.0 – Part 1

Author: [MVP] Tobias Zimmergren
Web: http://www.zimmergren.net

Prephase

I have previously written up a few articles on how you can get more from your SharePoint environment by enhancing it with AJAX, .NET 3.5 and Silverlight.

References to those articles can be found here:

My intention is to get a SharePoint / Silverlight article series going, and this is to be the first article in the series – How to get up and running!

Prerequisits

Must have:

Note: I’m not going to describe how you create a .xap file – you’ll find plenty of resources for that on the net. Just go google! (Live.com, yeah!)

Nice to have:

Part 1 – Step by step to configure your SharePoint environment for Silverlight 2.0

First of all, if you don’t want to do the manual .NET 3.5 settings in your web.config – there’s a great feature to take care of this on CodePlex which can be found under the Features project.

Step 1: Download, install and deploy the .NET 3.5 Web Config feature
  • Download the .NET 3.5 web.config feature from here
  • Install the .wsp into your SharePoint environment
  • Deploy the .wsp into your SharePoint environment to the appropriate Web Application
    image
  • Activate the feature for your Web Application (the one you deployed to)
    (This is done from Central Administration – Application Management – Manage Web Application Features)
    image 

Now we’re all set with the pre-configurations of the web.config – though there’s one more thing we need to manually do.

Step 2: Adding the final touches to web.config manually

Since the features project doesn’t include Silverlight by default (except for the Beta 2 version, which we’re not interested in..) you should now open up your web.config manually and

  • add the following line to <system.web> <compilation> <assemblies>:

<add assembly="System.Web.Silverlight,
    Version=2.0.5.0,
    Culture=neutral,
    PublicKeyToken=31bf3856ad364e35" />

It should look something like this:
image

Step 3: Add System.Web.Silverlight.dll to the GAC (Global Assembly Cache)

Add the System.Web.Silverlight.dll to the Global Assembly Cache (either drag’n’drop it into C:\Windows\assembly or use Gacutil.exe or use the default .NET Configuration Tool)

You’ll find the System.Web.Silverlight.dll assembly in the Silverlight 2.0 SDK folder, located here:

C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Libraries\Server\

Step 4: Set the correct MIME-type for the Silverlight .xap filetype

Go to your IIS management console (Start – Run - “inetmgr” without the quotes)

  • Select your Web Application from the list, and select properties:
    image
  • Choose “HTTP Headers” and then “MIME Types…”
    image
  • Add the MIME-type for Silverlight 2.0 Applications as shown:
    image
  • Okay, Okay, Okay (Press the buttons..)
  • Close the IIS manager as we will not need it anymore for the time being!

Now when all those fancy-pancy things are done – let’s get rolling with creating a simple Hello World Web Part using Silverlight 2.0, shall we?

Part 2 – Creating a first Web Part to host a Silverlight application

If you’ve read this far you should now be set up properly to create a Silverlight Web Part (Really, a Web part that loads the silverlight application and renders in the browser)

Step 1: Visual Studio 2008 time!

First of all, make sure you’ve got the .xap file in handy, then launch Visual Studio 2008 SP1.

  • Create a new Web Part project in your desired fashion – I’m using the WSS Extensions for ease:
    image
  • Add a reference to the System.Web.Silverlight assembly and to the System.Web.Extensions assembly, it should look something like this:
    image
     
  • Add the following using statements:
    Note: I’ve stripped down the default using statements, as they’re overkill for this – this is what you should need

    using System.Runtime.InteropServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.SilverlightControls;


  • Make an override on the OnInit method (We will dynamically add a ScriptManager to the current page, if there’s not one already):

    protected override void OnInit(System.EventArgs e)
    {
        base.OnInit(e);
        var sm = ScriptManager.GetCurrent(Page);
        if(sm == null)
        {
            var scriptManager = new ScriptManager();
            scriptManager.EnablePartialRendering = true;
            Page.Form.Controls.AddAt(0,scriptManager);
        }
    }

  • Write the following very simple code to load a Silverlight class into the Web Part, set it’s source to our .xap file and simply add it to the controls collection:  

    private Silverlight mySLControl;
    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        mySLControl = new Silverlight
        {
            ID = "HelloSilverlightControl",
            Width = new Unit(367), 
            Height = new Unit(150),
            Source = @"/_layouts/ZimmerLight/Hello/Hello.xap"
        };
        Controls.Add(mySLControl);
    }

  • Build and deploy the Web Part, and cross your fingers!
    (Using the WSS Extensions for Visual Studio, just rightclick the project and choose Deploy)
    image 
Step 2: Add the Web Part to a page
  • I’ve put my Web Part in a “Silverlight Web Parts” group – simply choose it and click add.
    image 
  • Voila, a fully functional Silverlight 2.0 Web Part rendered inside SharePoint – without any trouble!
    image


Summary and Download

As you’ve seen in this article, it isn’t too hard to get up and running with Silverlight 2.0 (and .NET 3.5 of course) and get our first Silverlight 2.0 Web Part spinning in SharePoint.

You should now be able to:

  • Configure your environment to use Silverlight 2.0
  • Hook up your Silverlight Application(s) in SharePoint
  • Enjoy the richness of Silverlight in SharePoint!

You can download the Visual Studio project from here

Comments and Feedback appreciated

Please leave your print in the comments, feedback is always nice :-)


Published: Dec-10-08 | 23 Comments | 0 Links to this post

"It's Silverlight, it's strong and tight, they got it right, try it tonight"

Over at Dan Wahlins blog you can listen to a new Silverlight song.

Go check it out and relax to some sweet Silverlight music.

- I know, I'm a geek.


Published: Apr-30-08 | 3 Comments | 0 Links to this post

Silverlight 1.0 seamless integration with SharePoint 2007 complete!

Author: Tobias Zimmergren
Url:
http://www.zimmergren.net

Yep. It's me again...

I managed to salvage most of the data from the bluescreen a couple of hours earlier (due to the persistent use of source control).

I'll cover this topic more in details in one of the days to come, for now - this is what it looks like:

 slclock

Please do comment!

Have a good night everybody! I sure will, now.


Published: Mar-13-08 | 6 Comments | 0 Links to this post

Bluescreen of Death on my VPC

I completed my integration project with Silverlight 1.0 and SharePoint 2007 - which doesn't requiry any configuration on your server, except to install my Web Part with the .wsp solution.

But...

Instead of giving you a nice guide on how to implement and integrate Silverlight, Microsoft gave me a Bluescreen of Death smacked in my face when I was copying my files to the source control environment.

 bluescreen

Anyhow, it's not such a big loss. I think most of the things are checked into the Source Control environment already, so i just need to set up a new VPC - seeing as this one doesn't even start anymore :S

Hang in there a few days and you'll have your Silverlight 1.0 integration served on a Silverplate!

Keep in touch.


Published: Mar-13-08 | 1 Comment | 0 Links to this post

Silverlight (2.0) Blueprints for SharePoint

Author: Tobias Zimmergren
Url:
http://www.zimmergren.net

Hi people, been really busy the last couple of weeks and havn't had the time to answer your mails nor write any new blogposts.

However, I just felt that I needed to get this link out there for you guys to check out in case you havn't already: http://www.ssblueprints.net/sharepoint/

"Open Source Source Code and Full Blueprint coming soon" - Sounds promising

While you check out that link, I'll try to figure out the topic of my next MOSS post ;)


Published: Mar-03-08 | 0 Comments | 0 Links to this post

Silverlight and SharePoint integration

I'm writing this post as a question/survey and want to know if there's any interest in actually posting a blog on some different integration-possibilities with SharePoint and Silverligt.

I've created a couple of smaller projects that uses SharePoint's exposed webservices to create a nice Silverlight application to present the information (in this case some info from the news-list) which then can be displayed nicely on a projector or in a store or why not on the LCD-TV's that a lot of companies have these days to display information to the people that visit the place. Or why not as a billboard - use your imagination.

With this post I'm just curious as to weather there's any interest in seeing such posts coming up, and if so - please leave me a comment in this post or email me using the contactlink.

Thanks for tuning in,
Time to fall asleep on the train here again.


Published: Nov-09-07 | 2 Comments | 0 Links to this post

Silverlight with Ian Blackburn

I'm on the train right now with two of my colleagues, heading to Stockholm to attend a Silverlight course held by Mr. Ian Blackburn himself.

I'll be sure to post some interesting stuff about Silverlight and SharePoint integration soon, as I've made a couple of integrations the past couple of days.

Cheers


Published: Nov-06-07 | 1 Comment | 0 Links to this post