【问题标题】:Adding Web Parts to the Page Instance based on Page Layout using Feature使用功能基于页面布局将 Web 部件添加到页面实例
【发布时间】:2010-11-23 09:29:39
【问题描述】:

我正在尝试使用功能将 Web 部件添加到页面布局的页面实例。我知道它应该通过 AllUsersWebPart 元素。我可以找到将默认 Web 部件添加到的参考页面布局(PortalLayouts 功能做到了)。我也在 onet.xml 中看到了同样的情况。我想知道是否可以基于页面布局创建页面实例并使用该功能向其中添加 Web 部件。

【问题讨论】:

标签: sharepoint sharepoint-2007 web-parts


【解决方案1】:

在功能激活事件处理程序内部 ...

获取页面以添加 webpart(在本例中 - default.aspx)

SPFile thePage = curWeb.RootFolder.Files["default.aspx"];

获取 Webpart 管理器

//get the web part manager

SPLimitedWebPartManager theMan = thePage.GetLimitedWebPartManager

(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

然后创建一个webpart实例

//add a new ThisWeekInPictures web part

ThisWeekInPicturesWebPart wpPix = new ThisWeekInPicturesWebPart();

wpPix.ImageLibrary = "Shared Pictures";

wpPix.Title = "My Pictures";

然后是 Webpart 操作

WebPartAction wpa = new WebPartAction(wpPix, WebPartAction.ActionType.Add,

"MiddleRightZone", 10)

最后添加 webpart ...

theMan.AddWebPart(wpa.wp, wpa.zoneID, wpa.zoneIndex);

它已经完成了......我们页面中的一个新网络部件,我希望这会有所帮助;)

更多信息请查看本文http://blogs.msdn.com/sharepoint/archive/2007/03/22/customizing-moss-2007-my-sites-within-the-enterprise.aspx

【讨论】:

    猜你喜欢
    • 2014-07-07
    • 1970-01-01
    • 1970-01-01
    • 2011-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-23
    • 2010-10-21
    相关资源
    最近更新 更多