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?


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: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.contenttypes.aspx





  • 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
  • 3
    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
  • 2
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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