[英]Adding Web Parts to the Page Instance based on Page Layout using Feature
I am trying to add the Web Parts to Page Instance of the Page Layout using a Feature.I know it should be through AllUsersWebPart element .I could find the reference of adding a Default Web Part to Page Layout ( PortalLayouts feature does it). 我正在尝试使用功能将Web部件添加到页面布局的页面实例。我知道它应该通过AllUsersWebPart元素实现。我可以找到将默认Web部件添加到页面布局的参考( PortalLayouts功能可以做到)。 Also I have seen same in onet.xml . 我在onet.xml中也看到了相同的内容 。 I wanted to know if it possible to create an instance of the page based on the Page layout and add web part to it using the feature. 我想知道是否可以基于页面布局创建页面实例,并使用该功能向其中添加Web部件。
Inside a feature activation event handler ... 在功能激活事件处理程序中...
Get the Page to add the webpart (in this case - default.aspx) 获取页面以添加Webpart(在本例中为default.aspx)
SPFile thePage = curWeb.RootFolder.Files["default.aspx"];
Get the Webpart Manager 获取Webpart Manager
//get the web part manager
SPLimitedWebPartManager theMan = thePage.GetLimitedWebPartManager
(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
Then create a webpart instance 然后创建一个Webpart实例
//add a new ThisWeekInPictures web part
ThisWeekInPicturesWebPart wpPix = new ThisWeekInPicturesWebPart();
wpPix.ImageLibrary = "Shared Pictures";
wpPix.Title = "My Pictures";
Then a Webpart Action 然后是Webpart动作
WebPartAction wpa = new WebPartAction(wpPix, WebPartAction.ActionType.Add,
"MiddleRightZone", 10)
And finnally add the webpart ... 最后添加Webpart ...
theMan.AddWebPart(wpa.wp, wpa.zoneID, wpa.zoneIndex);
And it's done ... a new webpart in our page, I hope this helps ;) 并完成了...我们页面中的新Webpart,希望对您有所帮助;)
For more informations please check this article http://blogs.msdn.com/sharepoint/archive/2007/03/22/customizing-moss-2007-my-sites-within-the-enterprise.aspx 有关更多信息,请检查本文http://blogs.msdn.com/sharepoint/archive/2007/03/22/customizing-moss-2007-my-sites-within-the-enterprise.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.