通过SharePoint2010客户端对象模型列出页面上所有的WebPart
本例中你将会学到如何通过Ecmascript获取并设置default.aspx页面上WebPart的标题信息。
ClientContext oClientContext = new ClientContext(“http://SPSite”); File oFile = oClientContext.Web.GetFileByServerRelativeUrl(“Default.aspx”); LimitedWebPartManager limitedWebPartManager = oFile.GetLimitedWebPartManager(PersonalizationScope.Shared); oClientContext.Load(limitedWebPartManager.WebParts, wps => wps.Include( wp => wp.WebPart.Title)); //-> Can include more properties oClientContext.ExecuteQuery(); if (limitedWebPartManager.WebParts.Count == 0) { throw new Exception(“No Web Parts on this page.”); } WebPartDefinition oWebPartDefinition = limitedWebPartManager.WebParts[1]; WebPart oWebPart = oWebPartDefinition.WebPart; oWebPart.Title = “My New Web Part Title”; oWebPartDefinition.SaveWebPartChanges(); oClientContext.ExecuteQuery(); }
参考资料
List all the web parts on sharepoint page client object model sharepoint 2010