1

我正在为 SharePoint 制作一个 WebPart,它将实例化 Silverlight UserControl 并为其提供一些数据。我的问题是,当我创建了我的示例 WebPart 并仅实例化 Silverlight 控件时,当 Web 部件添加到页面或显示在 Web 部件库中时,而不是呈现空白,呈现一个错误页面,显示“找不到文件”。日志文件中没有关于未找到哪个文件或引发此错误的原因的线索。这是我的代码:

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();
    }
  }
}

我在项目中添加了对 System.Web.Extensions 和 System.Web.Silverlight 的引用。它们位于 GAC 中,并且 Web 部件是在 SharePoint 所在的同一台计算机上编写和编译的。如果我将 CreateChildControls() 更改为:

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

我犯了同样的错误。此外,如果我删除 sl.Source 中的第一个斜杠,我会收到相同的错误,即使该文件存在于与 SharePoint 相同的应用程序池中的虚拟目录中。因此,由于仅实例化 Silverlight 对象时出现错误,因此我相信无法找到的文件不是我的 XAP。

SharePoint 找不到哪些文件,我该怎么办?

这是错误消息:

http://www.freeimagehosting.net/uploads/2dca8dbdfb.png

4

3 回答 3

2

嗨,我找到了有关如何让 Silverlight Web 部件在您的应用程序上运行的完整演练:http ://www.vbforums.com/archive/index.php/t-557072.html

如您所见,除了程序集注册之外,web.config 中还添加了更多内容。

于 2009-02-25T15:38:32.507 回答
1

启用 SilverLight 需要大量的 Web 配置修改。你加了那些?

于 2009-02-24T16:04:24.870 回答
0

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").

于 2009-08-13T08:52:31.643 回答