U2U Blog

for developers and other creative minds

Where to deploy my Silverlight XAP file?

Tomorrow I'll leave for my annual trip to TechEd US again in Orlando. Looking forward to spend time with my buddies Ted and Fitz, and the rest of the gang in the US. Fitz recently joined Nintex and we'll have to catch up on that. From what I read on his blog, Nintex is not all about workflows. This week they'll RTM an interesting reporting layer for SharePoint. Read more here.

Anyway, I am presenting my session first thing Thursday morning. Title is 'Light Up Your SharePoint Web Site with Microsoft Silverlight and AJAX' and I'll highlight techniques for working with Web 2.0 technologies in the SharePoint space. Focus will be on hosting the Silverlight applications, your options to transfer data back and forth, consuming Web Services and WCF services, databinding and more.

I'll show also different techniques for the deployment of the Silverlight XAP file. A XAP file is basically a ZIP file containing the Silverlight solution components such as the compiled XAML and code-behind, an application manifest and possibly one or more assemblies delivering Silverlight controls. There are to me three possible places where you can make the XAP file available and the final choice depends more or less on your scope.

  • Drop the XAP in the ClientBin of your IIS Web Application. This is the most popular approach and also the technique we have used for the BluePrint samples. If you deploy in this location, it means that the Silverlight application can be picked up by any SharePoint code that runs in the site collections and sites hosted on the IIS Web Application. One of the disadvantages with this approach is that it is not directly possible to have the copying of the XAP in the ClientBin operation as part of the manifest of your SharePoint solution delivering the containers for the application (e.g. a Web Part). That is why for the BluePrint, we modified the SharePoint Solution Installer so that this extra step was taking care for.
  • Drop the XAP in the 12 Folder. If the Silverlight application needs to be scoped wider, you have for example a custom field type (which is by default a global deployed SharePoint solution), it is good to deploy in a sub folder of the 12\Template\Layouts or in the 12\Template\ControlTemplates folder. The 12\ISAPI is also a candidate. Deploying here means that you can include all of the deployment steps in your SharePoint Solution.
  • Drop the XAP in a Document Library. This is very often now my preferred choice of place to drop the XAP. You can create one central document library within your site collection (or if you want a more narrow scope, for your site) where to drop the XAP files. Just like with the previous 12 folder location, you can include this deployment also nicely in your Feature that for example makes available the Web Part hosting the Silverlight application.

Say for example that you create a Web Part with the Visual Studio Extensions for WSS 3.0. You can add the XAP file as part of the Feature folder in your Solution Explorer.

image

A Module and a File element in the element manifest file (lines 9-11) can take care of the provisioning of the XAP during the activation of the Feature in an existing document library (e.g. named XAPS).

   1: <Elements Id="c1f27c3d-0fab-46dc-b04d-a070b2713bbd" xmlns="http://schemas.microsoft.com/sharepoint/" >
   2:     
   3:   <Module Name="WebParts" List="113" Url="_catalogs/wp">
   4:       <File Path="HelloDevDays.webpart" Url="HelloDevDays.webpart" Type="GhostableInLibrary" >
   5:           <Property Name="Group" Value="DevDays Web Parts"></Property>
   6:       </File>
   7:   </Module>
   8:  
   9:     <Module Name="XAP" Url="XAPS">
  10:         <File Path="HelloDevDays.xap" Url="HelloDevDays.xap" Type="GhostableInLibrary" />
  11:     </Module>
  12:     
  13: </Elements>

In the Web Part where you create the Silverlight control, you then can point (line 6) to the XAP file using the following code:

   1: protected override void CreateChildControls()
   2: {
   3:     base.CreateChildControls();
   4:  
   5:     Silverlight ctrl = new Silverlight();
   6:     ctrl.Source = SPContext.Current.Site.RootWeb.Url + "/XAPS/HelloDevDays.xap";
   7:     ctrl.ID = "HelloDevDays";
   8:     ctrl.Width = new Unit(400);
   9:     ctrl.Height = new Unit(300);
  10:     ctrl.Version = "2.0";
  11:  
  12:     this.Controls.Add(ctrl);
  13:  
  14: }

As said, a nice and clean way to include all of the Silverlight files in your SharePoint Solution so that no more additional steps need to be taken after the deployment of the Web Part.

It is also very easy to upgrade the XAP files this way. But don't forget to clear your browser cache when you do this. Download the Internet Explorer Developer Toolbar to help you with that.

Comments (2) -

  • kGdTjKtL

    12/9/2015 2:35:21 PM | Reply

    111182 483386You are the most effective, It is posts like this that maintain me coming back and checking this web site  regularly, thanks for the information! 326751

Loading