Monday, November 16, 2009

Sharepoint and Silverlight Setup

This blog main purpose is to keep up with my notes as I solve issues and problems while developing in SharePoint.

Deploying a Silverlight Control to SharePoint 2007

  1. Copy the System.web.Silverlight.dll into the GAC (Global Assembly Cache). Once you install the Silverlight on the server/development environment you will have the dll in the following location: C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Libraries\Server\System.Web.Silverlight.dll

  2. There are a couple of different approaches to deploying your Silverlight project to your web server. I have done several from just creating a ClientBin directory on the server to hosting in an Apache web server to be served in to a Joomla PHP application. My opinion the best place to deploy it is in the 12 hive. Main reason is most likely you are going to create a web part to deploy on your page. Or at a minium you are going to create a new feature to make deployment easy. So for my application I create a folder under the LAYOUTS directory in the 12 hive. For anyone not sure what the 12 hive is it is just the file structure SharePoint uses to store its modules ie Features, Masterpages, Styles, etc... It is located at:
    C:\Program Files (x86)\Common Files\Microsoft Shared\Web Server Extensions\12

    Under the 12 folder there are several folders but the one I am looking for is
    12\TEMPLATE\LAYOUTS

    Now create a folder to hold the silverlight .xap file 12\TEMPLATE\LAYOUTS\MyFeature and copy my .xap file to this location.

    Now of course I don't do this manually I use WSPBuilder and create this structure in the VS2008 application. And when you deploy it will handle putting it in the correct location.
    Now you can build and deploy your feature to SharePoint but it still will not work we have more to do.


  3. Before the web server can serve up the .xap file you will have to add some mime types to the virtual directory you are using to store the .xap file. Since I am storing my .xap file in the 12/TEMPLATES/LAYOUTS/... directory I am going to add the MIME Types to the LAYOUTS Directory.













  4. Now for some Web.Config file changes. Probably a good idea to make a backup copy of the web.config file before making changes...

    Add this under the <configSections> tag:

    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

    <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

    <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

    <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

    <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />

    <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />

    <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />

    <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />

    </sectionGroup>

    </sectionGroup>

    </sectionGroup>


    Add this under the <assemblies> tag:

    <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

    <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

    <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

    <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>


    Add this under the <pages> tag:

    <controls>

    <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

    <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

    </controls>


    Add this under the <httpHandlers> tag:

    <remove verb="*" path="*.asmx"/>

    <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

    <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

    <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>


    Add this under the <httpModules> tag:

    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>


    Add this under the <runtime> tag:

    <dependentAssembly>
    <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>

    <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>

    </dependentAssembly>

    <dependentAssembly>
    <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>

    <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>

    </dependentAssembly>


    Add this under the < configuration> tag:

    <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>

    <modules>
    <remove name="ScriptModule" />
    <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </modules>

    <handlers>
    <remove name="WebServiceHandlerFactory-Integrated"/>

    <remove name="ScriptHandlerFactory" />

    <remove name="ScriptHandlerFactoryAppServices" />

    <remove name="ScriptResource" />

    <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
    type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

    <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
    type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

    <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </handlers>

    </system.webServer>


  5. Now build your silverlight web part and make sure you are pointed to the correct location and it will work. Next will be a blog on building a Silverlight Web Part.