예제 #1
0
        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);
        }
예제 #2
0
        //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()
            }));
        }
예제 #3
0
 public static ModelNode AddContentTypeLink(this ModelNode model, ContentTypeId contentTypeId)
 {
     return ContentTypeLinkDefinitionSyntax.AddContentTypeLink(model, new ContentTypeLinkDefinition
     {
         ContentTypeId = contentTypeId.ToString()
     });
 }