SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.