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

Using object model I need to add an item to a list. The list has 4 custom content types. Depending on data provided I need the item to be of a specific content type.

How is this done?

Using SPListItem oItem = list.AddItem(); does not accept a content type as a parameter. Neither can you set it later it seems the property is read only.

Any ideas?

share|improve this question
    
I also have the same problem... can you please help me if you found the solution for that... thanks... –  user4928 Sep 28 '11 at 16:54
    
user4928 - if you have a simliar problem that my answer does not solve, then please create a new question and explain why my answer isn't relevant. The answer to your problem may help others! :) –  James Love Sep 28 '11 at 22:06
add comment

1 Answer 1

Use SPList.Items.Add() to return the item you're adding (as an instance of SPListItem), instead of SPList.AddItem().

Then you can update the ContentTypeId using myListItem["ContentTypeId"] to set the content type.

Here's an example: http://asadewa.wordpress.com/2007/11/19/adding-a-custom-content-type-specific-item-on-a-sharepoint-list/

share|improve this answer
add comment

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.