I have an event-handler feature that changes the content type of an item when it is added to a document library, however this will only work if the content type is allowed for that document library. My feature needs to be able to create this content type if it does not already exist before assigning it to an item, however I most likely will also need to add it to the specific document libraries before it becomes usable.
Is it is simple as just adding the content type to the list of the content types for the document library? :
SPListItem listItem = properties.ListItem;
SPList list = properties.ListItem.ParentList;
SPContentType baseContentType = web.ContentTypes[SPBuiltInContentTypeId.Document];
SPContentType type = new SPContentType(baseContentType, web.ContentTypes, "Custom Folder");
type.Fields.Add("Users", SPFieldType.User, false);
list.ContentTypes.Add(type);
list.Update();
Side question (bonus points ;) - The "Users" field above should be a multi-select people-picker field. Will the above work to create this field?
Thanks