So people are always asking me how do I get Silverlight to work in SharePoint? Then Paul Galvin and some other people told me why not post the steps. So here is what you want to do:
- Get Visual Studio 2008 and download SP1 from http://www.microsoft.com/downloads/details.aspx?familyid=FBEE1648-7106-44A7-9649-6D9F6D58056E&displaylang=en. The installer may stick at one part and may take an hour or two, so make sure you leave tons of time to spare.
- Get the Microsoft Silverlight Tools for Visual Studio 2008 with SP1 from http://www.microsoft.com/downloads/details.aspx?FamilyId=c22d6a7b-546f-4407-8ef6-d60c8ee221ed&displaylang=en.
- Get Expression Blend 2.0 from http://www.microsoft.com/downloads/details.aspx?FamilyId=5FF08106-B9F4-43CD-ABAD-4CC9D9C208D7&displaylang=en.
- Download Expression Blend SP1 from http://www.microsoft.com/downloads/details.aspx?FamilyId=EB9B5C48-BA2B-4C39-A1C3-135C60BBBE66&displaylang=en.
- Create a new Silverlight Application using the Silverlight Application Template in Visual Studio 2008 and Expression Blend 2.0
SharePoint specific instructions:
- Create a new Virtual Directory on your SharePoint Application in IIS (c:\inetpub\wwwroot\wss\virtualdirectories\webappfolder\) called ClientBin. Make sure the directory has Read and Run Permissions. This directory is where you will put all your compiled Silverlight files (XAP files).
- Check the MIME Types in IIS to see if .XAP and .XAML are included (this is added in Server 2008 automagically, but not necessarily in Server 2003). If these entries are not included add them by using the new button and type in Extension: XAML MIME Type:application/xaml+xml and for the second entry Extension: XAP MIME Type:application/x-silverlight-app. Adding these extensions as MIME Types makes them trusted extensions.
- Add the System.Web.Silverlight.dll to the Global Assembly Cache (click on Start and then Run and type in Assembly and hit Enter, you can drag the assembly into this window).
Note: Once you install the Silverlight Extensions for Visutal Studio this should be in the c:\program files directory under the SDK.
- Add a Safe Control to your Web .Config File by navigating to the IIS folder for your SharePoint Application (c:\inetpub\wwwroot\wss\virtualdirectories\webappfolder\). Open the file in NotePad or another editing program and look for the <SafeControls> Tag. Add this tag at the end of the entries:
<SafeControl Assembly="System.Web.Silverlight, Version=18.104.22.168, Culture=neutral,PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.SilverlightControls" TypeName="*" Safe="True" />
- Copy your XAP File into the ClientBin Directory you created above.
- Create a SharePoint Webpart and add a reference to System.Web.UI.SilverlightControls and add a using statement. You should be able to create a new control and reference it in the CreateChildControls like such:
public Silverlight MySilverlightControl;
protected override void CreateChildControls()
MySilverlightControl = new Silverlight();
MySilverlightControl.ID = "slControl";
MySilverlightControl.Source = "/ClientBin/MyXAPFile.xap";