예제 #1
0
        public void CreateContentTypes()
        {
            Web web = ClientContext.Web;
            ContentTypeCollection existingContentTypes = web.ContentTypes;

            ClientContext.Load(existingContentTypes);
            ClientContext.ExecuteQuery();

            foreach (GtContentType contentType in ContentTypes)
            {
                if (existingContentTypes.Any(item => item.Id.ToString().Equals(contentType.ID.ToString(CultureInfo.InvariantCulture))))
                {
                    // We want to add fields even if the content type exists (?)
                    AddSiteColumnsToContentType(contentType);
                }
                else
                {
                    var contentTypeCreationInformation = contentType.GetContentTypeCreationInformation();
                    var newContentType = existingContentTypes.Add(contentTypeCreationInformation);
                    ClientContext.ExecuteQuery();

                    // Update display name (internal name will not be changed)
                    newContentType.Name = contentType.DisplayName;
                    newContentType.Update(true);
                    ClientContext.ExecuteQuery();

                    AddSiteColumnsToContentType(contentType);
                }
            }
        }
예제 #2
0
        public override object GetRealSPObject()
        {
            if (realObject != null)
            {
                return(realObject);
            }

            object parentObj = base.ParentNode.SPObject;

            if (parentObj != null)
            {
                if (parentObj is ContentTypeCollection)
                {
                    ContentTypeCollection contentTypes = parentObj as ContentTypeCollection;

                    if (contentTypes.Any(c => c.Name == this.Title))
                    {
                        realObject = contentTypes.FirstOrDefault(c => c.Name == this.Title);
                        return(realObject);
                    }
                }
            }

            return(null);
        }