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.
Nope. If you load the webparts like that all you get are
SPListItem
s (which are from the gallery) and notSPWebPart
objects (which you'll realistically only get from instances that exist on a page - or from loading in via anSPWebPartManager
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 doSPListItem.File.OpenBinaryStream()
and fire it into anXmlReader
orXDocument
object for easier parsing.