Ejemplo n.º 1
0
        /// <summary>
        /// Create Content Type
        /// </summary>
        public static void CreateContentType(ClientContext clientContext, string ContentTypeName, string ContentTypeDescription, string ContentTypeId, string[] filedNames)
        {
            var contentType = CSOMUtil.GetContentTypeById(clientContext, ContentTypeId);

            // check if the content type exists
            if (contentType == null)
            {
                ContentTypeCollection contentTypeColl = clientContext.Web.ContentTypes;
                clientContext.Load(contentTypeColl);
                clientContext.ExecuteQuery();

                // Specifies properties that are used as parameters to initialize a new content type.
                ContentTypeCreationInformation contentTypeCreation = new ContentTypeCreationInformation();
                contentTypeCreation.Name        = ContentTypeName;
                contentTypeCreation.Description = ContentTypeDescription;
                contentTypeCreation.Group       = "Property Manager My App Content Types";
                contentTypeCreation.Id          = ContentTypeId;

                //// Add the new content type to the collection
                contentType = contentTypeColl.Add(contentTypeCreation);
                clientContext.Load(contentType);
                clientContext.ExecuteQuery();

                CSOMUtil.BindFieldsToContentType(clientContext, contentType, filedNames);
            }
        }