private SPContentType EnsureContentTypeExists(ref SPWeb web) { SPContentType cType = null; try { cType = web.ContentTypes[ContentTypeId]; } catch { /* expected: not found */ } if (cType == null) { int ctCounter = 0; string ctId = ContentTypeId.ToString(); string ctName = Name; while (web.AvailableContentTypes[new SPContentTypeId(ctId)] != null && ctCounter < 100) { ctCounter++; ctId = ContentTypeId.ToString() + ctCounter.ToString("00"); ctName = string.Concat(Name, ParentSchema.ContentTypeNameSchemaSeparator, ctCounter); } SPContentType.ValidateName(ctName); cType = new SPContentType(new SPContentTypeId(ctId), web.ContentTypes, ctName); cType.Group = ParentSchema.GroupName; cType.ReadOnly = false; web.ContentTypes.Add(cType); //myContentType.Update(); } return(cType); }
//public static DefinitionBase OnCreating(this DefinitionBase model, Action<ListDefinition, SPList> action) //{ // model.RegisterModelUpdatingEvent(action); // return model; //} //public static DefinitionBase OnCreated(this DefinitionBase model, Action<ListDefinition, SPList> action) //{ // model.RegisterModelUpdatedEvent(action); // return model; //} #endregion #region add content type public static ModelNode AddContentTypeLink(this ModelNode model, ContentTypeId contentTypeId) { return(ContentTypeLinkDefinitionSyntax.AddContentTypeLink(model, new ContentTypeLinkDefinition { ContentTypeId = contentTypeId.ToString() })); }
public static ModelNode AddContentTypeLink(this ModelNode model, ContentTypeId contentTypeId) { return ContentTypeLinkDefinitionSyntax.AddContentTypeLink(model, new ContentTypeLinkDefinition { ContentTypeId = contentTypeId.ToString() }); }