SharePoint Web Part Gallery details of each web part

1.3k views Asked by At

When using SPWeb.GetCatalog(SPListTemplateType.WebPartCatalog), it returns an SPList which of course contains a SPListItemCollection of the web parts in the web part gallery.

When looping through the items, is there any easy way to get properties of the web parts? Such as AllowClose, CatalogIconImageUrl, etc...

I know I can probably accomplish this using the listItem.OpenBinaryStream etc and loading the xml of the .webpart file, but I wondered if there was an easier way to do this.

1

There are 1 answers

0
James Love On BEST ANSWER

Nope. If you load the webparts like that all you get are SPListItems (which are from the gallery) and not SPWebPart objects (which you'll realistically only get from instances that exist on a page - or from loading in via an SPWebPartManager object [and even then loading from the gallery, you would need to extract the XML in exactly the same way anyway]). You'll have to do SPListItem.File.OpenBinaryStream() and fire it into an XmlReader or XDocument object for easier parsing.