簡體   English   中英

使用功能基於頁面布局將Web部件添加到頁面實例

[英]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,希望對您有所幫助;)

有關更多信息,請檢查本文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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM