Tuesday, January 10, 2012

Find all ContentByQueryWebParts from the page programatically

Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager manager = web.GetLimitedWebPartManager("Pages/default.aspx", PersonalizationScope.Shared);

foreach (Microsoft.SharePoint.WebPartPages.WebPart webPart in manager.WebParts)
{
 string type name="Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart, Microsoft.SharePoint.Publishing, Version=14.0.0.0,   Culture=neutral,    PublicKeyToken=71e9bce111e9429c";

 Type type = webPart.GetType();
 if (type.FullName.Contains("ContentByQueryWebPart")
 {
  //then it is ContentByQueryWebPart
 }
}