1
我試圖使用功能將Web部件添加到頁面佈局的頁面實例。我知道它應該通過AllUsersWebPart元素。我可以找到將默認Web部件添加到頁面佈局的參考(PortalLayouts功能)。我也見過onet.xml。我想知道是否可以根據頁面佈局創建頁面實例,並使用該功能將Web部件添加到它。使用功能基於頁面佈局將Web部件添加到頁面實例
我試圖使用功能將Web部件添加到頁面佈局的頁面實例。我知道它應該通過AllUsersWebPart元素。我可以找到將默認Web部件添加到頁面佈局的參考(PortalLayouts功能)。我也見過onet.xml。我想知道是否可以根據頁面佈局創建頁面實例,並使用該功能將Web部件添加到它。使用功能基於頁面佈局將Web部件添加到頁面實例
裏面一個功能激活事件處理程序...
讓頁面添加Web部件(在這種情況下 - 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";
然後一個web部件動作
WebPartAction wpa = new WebPartAction(wpPix, WebPartAction.ActionType.Add,
"MiddleRightZone", 10)
而且finnally添加的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
類似於http://stackoverflow.com/questions/599228/add-webpart-to-default-wss-page-via-feature – 2009-10-01 12:39:44