SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

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

I would like to download the metadata for an item. I don't want all the columns because SharePoint adds bunch of them, e.g. date, name, etc. that I don't need. I just want to download the columns for an item's content type.

For example, my document.doc has content type G2 associated with it (about 12 custom columns). I just want the info from these columns or fields.

share|improve this question
I tried string strXML = oItem.Xml.ToString(); but this is a no no. it gives me so much junk that I dont want. I just want the whatever the content type columns are for the item in question. – user2492 Mar 4 '11 at 17:11… This wont help either. – user2492 Mar 4 '11 at 17:17

You could write a a bunch of CAML queries and feed those to an SPSiteDataQuery. To get only the fields needed, User code to get to the SPContentType's Fields, then for each Contenttype execute the SPSiteDataQuery, including the fields in the content type in the query's ViewFields:

pseudo code

  • define the list of contenttype id's that should be included in a variable
  • define a variable that holds field id's of fields to be excluded from a query
  • get the list of content types (SPSite.RootWeb.ContentTypes)
  • loop through those content types
  • if current content type in loop does not exist in list of content types to be queried (as defined in variable), continue
  • if content type should be included, get it's fields
  • build an SPSiteDataQuery, adding the current SPContentType's fields to the query's ViewFields
  • execute the query (excluding any field as defined in exclusion variable)
  • export the resulting DataTable to an Xml File (or any other format)
share|improve this answer

You can create a view of the data to show you the desired metadata then export that to Excel. You'll end up with 1 extra column, the file location, but that's easy enough to remove.

share|improve this answer
Eric - I have over 500+ document libraries and I am using about 12 different content type for these document libraries. Are you saying create custom view for each document libraries in sharepoint? and then read the columns from the view? a code snippet would help. I am getting lost in translation here. – user2492 Mar 4 '11 at 17:10
That's going to be too much work then in my method. I assumed it was a one off scenario. I have no idea how to do that with code. – Eric Alexander Mar 4 '11 at 20:36

Your Answer


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