Silverlight WebPart in Sharepoint

I am new to Silverlight 2.0 and I am actually trying to deploy Silverlight as webpart in Sharepoint 2007.

I made the following installations:

  • VS 2008 Service Pack 1 (SP1)
  • Silverlight 2.0 SDK and exe
  • Silverlight Tools for VS 2008
  • MOSS 2007

I created a sample Silverlight application and got the xap file from the bin directory of the solution.

Then I wrote a standard Sharepoint webpage with a link to Web.Extensions

and Microsoft.Silverlight

dll:

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Web.UI.SilverlightControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace SLWeb_Part1
{
    [Guid("c890f832-05d2-4724-ae25-5f34c827c6c2")]
    public class SLWeb_Part1 : System.Web.UI.WebControls.WebParts.WebPart
    {
        public SLWeb_Part1()
        {
        }

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription("Location of the Silverlight XAP package"),
        WebDisplayName("XAP Location")]
        public string XAPSource { get; set; }

        [WebBrowsable(true),
        Personalizable(PersonalizationScope.User),
        WebDescription("Silverlight Controld ID "),
        WebDisplayName("Control ID")]
        public string ControlID { get; set; }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
            if (scriptManager == null)
            {
                scriptManager = new ScriptManager();
                this.Controls.Add(scriptManager);
            }
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            Silverlight sl = new Silverlight();
            sl.Source = XAPSource;
            sl.ID = ControlID;
            sl.Width = new Unit(400);
            sl.Height = new Unit(400);

            this.Controls.Add(sl);
        }
    }

      

I also deployed the same to the Sharepoint site, then I made an entry in the site file of the Sharepoint site to enable the Silverlight build and Web.Extension, for example:

<add assembly="System.Web.Silverlight, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

      

Then I enabled application/x-silverlight-app

as the MIME type for the web application in IIS.

After doing all this ... I could browse the site as usual, but I could not see the Silverlight component working ... and it also does not throw any errors ...

Can anyone help me solve this problem as early as possible? Skip any steps in the configuration?

Thanks in advance.

0


source to share


4 answers


I managed to solve my problem by making sure my SharePoint web.config was configured correctly for ASP.NET AJAX. It is not configured correctly by default. See this site for details on how to do this:

ASP.NET AJAX Integration with SharePoint



Good luck!

+1


source


A better starting point would be reading the Silverlight schema for SharePoint from the people at u2u - http://www.codeplex.com/SL4SP p>



0


source


I am trying to do the exact same thing and have the same problem. I traced it down to what I think is the issue with the ScriptManager.

In a normal ASPX page (where my Silverlight works correctly), the ScriptManager seems to add this to the page:

<script src="/ScriptResource.axd?d=Un3ROg6ZO8lU8fUlhDz-soUWbkyxgh5pk-teueIPxbpft-XX1Z5TrN4P3iF-wiGinTLoxOt5mA420kQULjqoDnUjO5gjwu0sPPlLgxOq-5g1&amp;t=ffffffff888edfb1" type="text/javascript">
</script>
<script type="text/javascript"> 
//<![CDATA[
if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.');
//]]>
</script>

      

However, the ScriptManager added by my WebPart does not add this code to the page. So, when the browser reaches the following code that tries to load Silverlight, it fails because the Sys object is undefined.

<script type="text/javascript"> 
//<![CDATA[
Sys.UI.Silverlight.Control.createObject('Xaml1_parent', '\u003cobject type="application/x-silverlight-2" id="Xaml1" style="height:100%;width:500px;">\r\n\t\u003cparam name="MinRuntimeVersion" value="2.0.31005.0">\r\n\r\n\t\u003c/param>\u003ca href="http://go2.microsoft.com/fwlink/?LinkID=114576&amp;v=2.0">\u003cimg src="http://go2.microsoft.com/fwlink/?LinkID=108181" alt="Get Microsoft Silverlight" style="border-width:0;" />\u003c/a>\r\n\u003c/object>');
//]]>
</script>

      

Hope this helps at least to get the discussion going.

0


source


After going to the Toms post change the webconfig system.web.extensions values ​​from 1.06 ... to 3.5.0.0 when using .net 3.5

0


source







All Articles