Get all the web parts from the page using client object model


using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Microsoft.SharePoint;
using
Microsoft.SharePoint.Client;
using
Microsoft.SharePoint.Client.WebParts;


namespace
ClientObjectModel
{
class Program
{
static void Main(string[] args)
{
//Get all the web parts from the page using client object model

ClientContext context = new ClientContext("http://serverName:1111");
File file = context.Web.GetFileByServerRelativeUrl("/Shared%20Documents/Forms/AllItems.aspx");
LimitedWebPartManager wpm = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
context.Load(wpm.WebParts,
wps => wps.Include(
wp => wp.WebPart.Title));
context.ExecuteQuery();
foreach (WebPartDefinition wpd in wpm.WebParts)
{
WebPart wp = wpd.WebPart;
Console.WriteLine(wp.Title);
}
Console.ReadLine();
}
}
}