Exercise 1: Automating Silverlight application and Silverlight Web Part Deployment
In this exercise, you will use Visual Studio 2010 to create a SharePoint Solution Package that deploys a Silverlight application and a web page that includes a pre-configured Silverlight Web Part to display the Silverlight application.
Task 1 – Creating a WSP to Deploy the Silverlight Application
In this task, you will use Visual Studio to create a SharePoint Solution Package that deploys a Silverlight application to a SharePoint 2010 site collection.
- Using Visual Studio 2010, open the Sample.Silverlight.App.sln Visual Studio Solution at the following location <INSTALL\Labs\AutomatingSilverlightWebPartDeployment\Source\Before \Sample.Silverlight.App.
- In Visual Studio 2010, click File>> Add >> New Project to add a new project. (Figure 1)
- In the Installed Templates, select Visual C# -> SharePoint -> 2010 and select Empty SharePoint Project.
- Under Name: enter SharePoint.Silverlight.Deployment.
In the Location: textbox enter <INSTALL\Labs\AutomatingSilverlightWebPartDeployment\Source\Before and click OK.
Figure 1
Create an Empty SharePoint project.
- In the SharePoint Customization Wizard, enter the URL for your on premise instance of SharePoint 2010 (i.e. https://intranet.contoso.com).
- Select Deploy as a sandboxed solution and click Finish.
- Right-click the Sample.Silverlight.App project and choose Add -> New Item.
- Select Visual C# -> SharePoint -> 2010 -> Module.
In the Add New Item dialog, under Name: enter Silverlight and click Add.
- Include the Silverlight.CSOM project output in the Silverlight.Client.CSOM.
In the Solution Explorer, Right-click the Silverlight module and select Properties.
- Click on Project Output References row and click the Ellipse button to open the Project Output References dialog.
- Click Add and select a new project output reference.
- Under Members: select the SharePoint.Silverlight.Deployment project.
- Select the Project Name dropdown under SharePoint.Silverlight.Deployment properties: in the right hand panel select Sample.Silverlight.App.
Using the Deployment Type dropdown, select ElementFile.
Figure 3
Project Output References
- Expand the Deployment location row.
- Delete the value in the Path row.
- Click OK to exit the dialog.
- In the Solution Explorer, right click the Sample.txt file and select Delete.
- Click OK.
- Double-click the Elements.xml file under the Silverlight module.
Add the following code to the Module element.
Url="_catalogs/masterpage/xaps"
Add the following code to the File element.
Type="GhostableInLibrary"
Make sure the XML is exactly as it appears below:
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="https://schemas.microsoft.com/sharepoint/"> <Module Name="Silverlight" Url="_catalogs/masterpage/xaps"> <File Path="Sample.Silverlight.App.xap" Url="Sample.Silverlight.App.xap" Type="GhostableInLibrary"/> </Module> </Elements>
- Save the Elements.xml file.
- Add a module to deploy a custom ASPX page that includes a Silverlight Web Part configured to display the new Silverlight application.
- Right-click the SharePoint.Silverlight.Deployment SharePoint project and choose Add-> New Item.
- Select Visual C# -> SharePoint-> 2010 -> Module.
- Name the module CustomPages.
- Click Add.
- In the Solution Explorer, right-click the Sample.txt file and select Delete.
- Click OK.
- Add the TimeEntrySearchPage.aspx included in the student files to the module.
- Right-click the CustomPages module.
- Select Add >> Existing Item.
- Browse to the <INSTALL\Labs\AutomatingSilverlightWebPartDeployment\Source\Before\SilverlightTestPage.aspx file and select it.
- Click Add.
Open the Elements.xml file included in the CustomPages module and replace the content with the following Xml:
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="https://schemas.microsoft.com/sharepoint/"> <Module Name="CustomPages"> <File Url="SilverlightTestPage.aspx" Path="CustomPages\ SilverlightTestPage.aspx" Type="Ghostable" > <Property Name="Title" Value="Silverlight Test Page" /> <Property Name="Description" Value="Test Page to demonstrate how to deploy a web page with the Silverlight Web Part preconfigured to display a Silverlight application." /> <AllUsersWebPart WebPartOrder="1" WebPartZoneID="Main" ID="SilverlightWebPart"> <![CDATA[ <webParts> <webPart xmlns="https://schemas.microsoft.com/WebPart/v3"> <metaData> <type name="Microsoft.SharePoint.WebPartPages.SilverlightWebPart, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /> <importErrorMessage>Cannot import this Web Part.</importErrorMessage> </metaData> <data> <properties> <property name="HelpUrl" type="string" /> <property name="AllowClose" type="bool">True</property> <property name="ExportMode" type="exportmode">All</property> <property name="Hidden" type="bool">False</property> <property name="AllowEdit" type="bool">True</property> <property name="Direction" type="direction">NotSet</property> <property name="TitleIconImageUrl" type="string" /> <property name="AllowConnect" type="bool">True</property> <property name="HelpMode" type="helpmode">Modal</property> <property name="CustomProperties" type="string" null="true" /> <property name="AllowHide" type="bool">True</property> <property name="Description" type="string">A web part to display a Silverlight application.</property> <property name="CatalogIconImageUrl" type="string" /> <property name="MinRuntimeVersion" type="string" null="true" /> <property name="ApplicationXml" type="string" /> <property name="AllowMinimize" type="bool">True</property> <property name="AllowZoneChange" type="bool">True</property> <property name="CustomInitParameters" type="string" null="true" /> <property name="Height" type="unit">250px</property> <property name="ChromeType" type="chrometype">Default</property> <property name="Width" type="unit">800px</property> <property name="Title" type="string">Silverlight Web Part</property> <property name="ChromeState" type="chromestate">Normal</property> <property name="TitleUrl" type="string" /> <property name="Url" type="string">~site/_catalogs/masterpage/xaps/Sample.Silverlight.App.xap</property> <property name="WindowlessMode" type="bool">True</property> </properties> </data> </webPart> </webParts> ]]> </AllUsersWebPart> </File > </Module> </Elements>
- Save the Elements.xml file.
Task 2 – Deploying and Testing the Silverlight Application and Web Page Pre-configured with the Silverlight Web Part
In this task, you will test the deployment of the Silverlight application and web page.
- In the Solution Explorer, right-click the SharePoint.Silverlight.Deployment project and choose Deploy.
- Once the status bar displays deploy succeeded, open Internet Explorer and navigate to https://intranet.contoso.com/silverlighttestpage.aspx.
Verify the Silverlight Web Part displays the Silverlight.Sample.App Silverlight application on the SharePoint page.
Figure 4
Silverlight Web Part
Exercise 1 Verification
In order to verify that you have correctly performed all steps of exercise 1, proceed as follows:
Verification 1
In this verification, you will browse to the SharePoint page where you added the Content Editor Web Part to validate it displays the Silverlight.Sample.App Silverlight application that is running on the web site hosted by Visual Studio 2010.
- Open Internet Explorer and navigate to https://intranet.contoso.com/silverlighttestpage.aspx.
Verify the Silverlight Web Part displays the Silverlight.Sample.App Silverlight application on the SharePoint page.
Figure 5
Silverlight Web Part