views:

1143

answers:

3

Hi, I'm making a WebPart for SharePoint that will instantiate a Silverlight UserControl and feed it some data. My problem is that when I have created my sample-WebPart and just instantiate a Silverlight control, the webpart, when added to a page or displayed in the webpart gallery, instead of rendering blank, renders an error page saying "File Not Found". No clue in the logfiles to what file was not found or why this error is thrown. Here is my code:

using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.SilverlightControls;

namespace TestSLWP {
  public class CustomWebPart1 : WebPart {

    protected override void CreateChildControls() {
      Label lblHello = new Label();
      lblHello.Text = "Hello";
      Controls.Add(lblHello);
      Silverlight sl = new Silverlight();
    }
  }
}

I've added references to System.Web.Extensions and System.Web.Silverlight to the project. They are in the GAC, and the webpart is written and compiled on the same computer that SharePoint resides. If I change the CreateChildControls() to be:

protected override void CreateChildControls() {
  Silverlight sl = new Silverlight();
  sl.ID = "CustomWebPart1SL";
  sl.Source = "/Silverlight/CustomWebPart.xap";
  this.Controls.Add(sl);
}

I get the same error. Also if I remove the first slash in sl.Source I get the same error, even though the file is present in a virtual directory in the same application pool as SharePoint. I therefore, and because the error comes with just instantiating the Silverlight object, believe that the file that cannot be found is not my XAP.

What file can't SharePoint find and what can I do about it?

Here's the error message:

+1  A: 

Enabling SilverLight requires a lagre amount of web config modifications. Did you add those?

webwires
I can't say that I did a large amount of web.config modifications, I only added the assembly "System.Web.Silverlight, Version=2.0.5.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" to SafeControls. I also added the two mime-types to IIS. Are there other modifications I should be doing?
niklassaers-vc
niklassaers-vc
Thanks for the hint, together with the link below I was able to get this file the way it should be. :-)
niklassaers-vc
+2  A: 

Hi I found a complete walk through on how to get Silverlight web parts get running on your application: http://www.vbforums.com/archive/index.php/t-557072.html

As you can see there are added some more things to the web.config beside your assembly registration.

Flo
Thanks for the link, I'll go through it thoroughly and get back to you with my results :-)
niklassaers-vc
This page was great for pointing out exactly what needed to go into Web.Config, thanks a lot. :-) I had no idea I was missing that much in it. Also, even though I had checked and double-checked, the DLL was missing in the GAC, and that probably gave me the "File Not Found." exception. Thanks a lot!
niklassaers-vc
A: 

There could be the problem with your storage folder with silverlight control. You must register path to this storage as safe in web.config (for example find in web.config line with "~/controltemplates").

Igor