Thursday, April 8, 2010

SilverLight WebPart

To Develop Silverlight WebPart
1.Create a Silverlight Application first, compile it to get the .XAP file.
2.Create a WebPart project add the Silverlight .XAP file like this
Example

protected override void CreateChildControls()
{
//base.CreateChildControls();
System.Web.UI.SilverlightControls.Silverlight myMediaCtrl = new System.Web.UI.SilverlightControls.Silverlight();
myMediaCtrl.ID = "RajMediaPlayer";
myMediaCtrl.Source = "http://rajwss.com/rajss1/monkDocumentLib/RajMediaPlayer.xap";// media files can be uploaded to this same Document Library.
myMediaCtrl.Width = new System.Web.UI.WebControls.Unit(900);
myMediaCtrl.Height = new System.Web.UI.WebControls.Unit(650);

this.Controls.Add(myMediaCtrl);

}
3.Compile it and deploy to the server.
Server Side changes

1.Install Silverlight SDK on the Sharepoint Server.
The Silverlight SDK can be downloaded from : http://www.microsoft.com/downloads/details.aspx?FamilyID=8D933343-038F-499C-986C-C3C7E87A60B3&displaylang=en
After the SDK has been installed make sure the System.Web.Silverlight.dll assembly has been registered in the GAC.
i also installed Silverlight.exe(V 3.0) in the server(not required though)
2. Make the following changes to the SharePoint Site web.config file
Add the following to the configuration (copy to NotePad Replace lt; to < & gt; to > )

Add the following to the lt;configurationgt;lt;configSectionsgt; xml:

lt;sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"gt;
lt;sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"gt;
lt;section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /gt;
lt;sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"gt;
lt;section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" /gt;
lt;section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /gt;
lt;section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /gt;
lt;section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /gt;
lt;/sectionGroupgt;
lt;/sectionGroupgt;
lt;/sectionGroupgt;

Add the following to the lt;configurationgt;lt;Sharepointgt;lt;SafeControlsgt; xml:

lt;SafeControl Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TypeName="*" Safe="True" /gt;
lt;SafeControl Assembly="System.Web.Silverlight, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.SilverlightControls" TypeName="*" Safe="True" /gt;

Add the following to the lt;configurationgt;lt;system.webgt;lt;httpHandlersgt; xml:

lt;remove verb="*" path="*.asmx" /gt;
lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /gt;
lt;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" /gt;
lt;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" /gt;

Add the following to the lt;configurationgt;lt;system.webgt;lt;compilationgt;lt;assembliesgt; xml:

lt;add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /gt;
lt;add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /gt;
lt;add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /gt;
lt;add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /gt;
lt;add assembly="System.Web.Silverlight, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /gt;

Add the following to the lt;configurationgt;lt;system.webgt;lt;pagesgt; xml:

lt;controlsgt;
lt;add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /gt;
lt;add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /gt;
lt;/controlsgt;

Add the following to the lt;configurationgt;lt;runtimegt;lt;assemblyBindinggt; xml:

lt;dependentAssemblygt;
lt;assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" /gt;
lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /gt;
lt;/dependentAssemblygt;
lt;dependentAssemblygt;
lt;assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" /gt;
lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /gt;
lt;/dependentAssemblygt;

Add the following to the lt;configurationgt; xml:

lt;system.webServergt;
lt;validation validateIntegratedModeConfiguration="false" /gt;
lt;modulesgt;
lt;remove name="ScriptModule" /gt;
lt;add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /gt;
lt;/modulesgt;
lt;handlersgt;
lt;remove name="WebServiceHandlerFactory-Integrated" /gt;
lt;remove name="ScriptHandlerFactory" /gt;
lt;remove name="ScriptHandlerFactoryAppServices" /gt;
lt;remove name="ScriptResource" /gt;
lt;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" /gt;
lt;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" /gt;
lt;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" /gt;
lt;/handlersgt;
lt;securitygt;
lt;authorizationgt;
lt;add accessType="Allow" users="" /gt;
lt;add accessType="Allow" users="?" /gt;
lt;/authorizationgt;
lt;/securitygt;
lt;/system.webServergt;

3.To add the Silverlight XAP to the IIS MIME-Type complete the following steps:
Open IIS
Open up the properties for the IIS Web Server
Click MIME Types...
Click New...
Enter ".xap" for the Extension
Enter "application/x-silverlight-app" for the MIME type
Click Ok, Ok, Apply
4. Restart IIS.

5.Add the deployed WebPart to the page.

For the complete code check
http://www.vbforums.com/archive/index.php/t-557072.html

No comments:

Post a Comment