Get all the web parts from the page using client object model
In this blog we will be seeing how to 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();
}
}
}


Muthu VPosted Jul 31, 2016, 11:57 PM EDT
Wp.GetType().FullName does not return us the exact WebPart type. This always returns us Microsoft.SharePoint.Client.WebParts.WebPart. Is there any way to find exactly the WebPart type
nata rajanPosted Jan 9, 2013, 5:51 AM EST
Nice code snippet. Thank you Vijai. Can you please post the sample code to to get the rendered data from webpart(site page). I am very new to this.