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 am planning on rolling my own web part where users can select a content type and it will generate search fields based on the columns. Am I right to write my own or is there a better way to do this that I am unaware of?

Somewhat related to this question:

Can I get the source for the out-of-the-box web parts in SharePoint 2010?

share|improve this question
up vote 5 down vote accepted

You can enumerate the content types in a site collection using the object model, and then for each Content Type you can get the Fields to see what fields should be displayed.

Populate a dropdown box for content types, and handle SelectedIndexChanged event handler to populate a second dropdown box with the Fields' titles found in the FieldLinks you get for the selected Content Type.

Useful Links:

share|improve this answer
I would want to use the FieldLinks and not the Fields member of the SPContentType? – Abe Miessler Apr 8 '11 at 21:09
Well spotted, I'm used to adding fields to content types programmatically, force of habit. I'll update my answer. – James Love Apr 8 '11 at 21:16
Just to complement James' answer, I would make something that can enumerate only specific content types, but allow the user to choose (i.e. create a custom toolpart) – Neil Richards Apr 8 '11 at 21:41
Going a step further from Neil's complement, let have you pick a content type and let it only show the child content types. Dude, you're giving us ideas ;) – James Love Apr 8 '11 at 21:43

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.