[英]Adding Web Parts to the Page Instance based on Page Layout using Feature
我正在尝试使用功能将Web部件添加到页面布局的页面实例。我知道它应该通过AllUsersWebPart元素实现。我可以找到将默认Web部件添加到页面布局的参考( PortalLayouts功能可以做到)。 我在onet.xml中也看到了相同的内容 。 我想知道是否可以基于页面布局创建页面实例,并使用该功能向其中添加Web部件。
在功能激活事件处理程序中...
获取页面以添加Webpart(在本例中为default.aspx)
SPFile thePage = curWeb.RootFolder.Files["default.aspx"];
获取Webpart Manager
//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);
并完成了...我们页面中的新Webpart,希望对您有所帮助;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.