在功能激活事件处理程序内部 ...
获取页面以添加 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