Hosting the Silverlight Application in SharePoint 2010

The Silverlight application created in the previous section was hosted on an ASP.NET page, but we now want to host the Silverlight application on a SharePoint site. Hosting a Silverlight application involves two steps:

1. Deploy the XAP file either to some folder in <14 Hive>, ideally the Layouts folder, or to some document library in the SharePoint site.

2. Reference the XAP file in the out of the box Silverlight web part or some custom web part.

Add a new Empty SharePoint project to the HelloWorldSLApp solution and name it HelloWorldSLDeploy. Right-click the SharePoint project and click Add, SharePoint “Layouts” Mapped Folder. The Layouts folder gets added to the Project. A subfolder HelloWorldSLDeploy also gets added under the Layouts folder.

Right-click the HelloWorldSLApp Silverlight project and open the properties. Go to Build Events and add the following in the Post-build event command line section.

xcopy /Y $(ProjectDir)$(OutDir)HelloWorldSLApp.XAP $(SolutionDir)HelloWorldSLDeployLayoutsHelloWorldSLDeploy

Build the HelloWorldSLApp project. If the build is successful the XAP gets copied to the LayoutsHelloWorldSLDeploy folder in the HelloWorldSLDeploy project. Include the XAP file in the project. The final solution structure is shown in Figure 9.7.

Image

Figure 9.7. HelloWorldSL-Deploy project structure

Now any changes in the Silverlight project are reflected in the HelloWorldSLApp.xap file in the HelloWorldSLDeploy project thanks to your Post-build command. This XAP file gets deployed to the <14 Hive>LayoutsHelloWorldSLDeploy folder. Deploy the HelloWorldSLDeploy solution.

Browse to the SharePoint site and add the Silverlight web part. This web part is available under the Media and Content category.

You are prompted to specify the URL of the Silverlight XAP file after adding the web part. Specify the URL as /_Layouts/HelloWorldSLDeploy/HelloWorldSLApp.xap and click OK. Save the page, and you should see the Silverlight application hosted within the SharePoint site.

Hosting the Silverlight application within a custom web part is a simple exercise. You just need to generate the object tag with the appropriate parameters or use the ASP.NET Silverlight control.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset