Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

1 Answer 1

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

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcontenttype.aspx

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcontenttype.fields.aspx

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist.aspx

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedindexchanged.aspx

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
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

 
discard

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.