Пример #1
0
        public void DeleteAllCustomContentTypes()
        {
            Web web = ClientContext.Web;
            ContentTypeCollection existingContentTypes = web.ContentTypes;

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

            var contentTypeGroups = new List <string>();

            foreach (
                ShContentType contentType in
                ContentTypes.Where(contentType => !contentTypeGroups.Contains(contentType.Group)))
            {
                contentTypeGroups.Add(contentType.Group);
            }
            List <ContentType> contentTypes =
                existingContentTypes.ToList()
                .OrderBy(ct => ct.Id.ToString())
                .Where(ct => contentTypeGroups.Contains(ct.Group))
                .ToList();

            for (int i = contentTypes.Count - 1; i >= 0; i--)
            {
                contentTypes[i].DeleteObject();
                try
                {
                    ClientContext.ExecuteQuery();
                }
                catch
                {
                    Console.WriteLine("Could not delete content type '" + contentTypes[i].Name + "'");
                }
            }
        }
Пример #2
0
        /// <summary>
        /// This method will get all content types from the specified content type group and will filter out the content types that user has selected
        /// when creating the matter
        /// </summary>
        /// <param name="clientContext">The sharepoint context object</param>
        /// <param name="contentTypesNames">Content Type Names that user selected in the create matter screen</param>
        /// <param name="client">The client object which contains information for which client the matter is getting created and the url of the client</param>
        /// <param name="matter">The matter information that is getting created</param>
        /// <returns></returns>
        public IList <ContentType> GetContentTypeData(ClientContext clientContext, IList <string> contentTypesNames, Client client, Matter matter)
        {
            ContentTypeCollection contentTypeCollection         = null;
            IList <ContentType>   selectedContentTypeCollection = new List <ContentType>();

            try
            {
                if (null != clientContext && null != contentTypesNames)
                {
                    Web    web             = clientContext.Web;
                    string contentTypeName = contentTypesConfig.OneDriveContentTypeGroup.Trim();
                    contentTypeCollection = web.ContentTypes;
                    clientContext.Load(contentTypeCollection, contentType => contentType.Include(thisContentType => thisContentType.Name).Where(currContentType => currContentType.Group == contentTypeName));
                    clientContext.ExecuteQuery();
                    selectedContentTypeCollection = GetContentTypeList(contentTypesNames, contentTypeCollection.ToList());
                }
            }
            catch (Exception exception)
            {
                customLogger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable);
                throw;
            }

            return(selectedContentTypeCollection);
        }
Пример #3
0
        /// <summary>
        /// Gets the list of content types along with their properties.
        /// </summary>
        /// <param name="clientContext">Client context</param>
        /// <param name="contentTypesNames">List of Content Type Names associated with matter</param>
        /// <param name="requestObject">Request Object</param>
        /// <param name="client">Client Object</param>
        /// <param name="matter">Matter Object</param>
        /// <returns>List of content types</returns>
        internal static IList <ContentType> GetContentTypeData(ClientContext clientContext, IList <string> contentTypesNames, RequestObject requestObject = null, Client client = null, Matter matter = null)
        {
            ContentTypeCollection contentTypeCollection         = null;
            IList <ContentType>   selectedContentTypeCollection = new List <ContentType>();

            try
            {
                if (null != clientContext && null != contentTypesNames)
                {
                    Web web = clientContext.Web;
                    contentTypeCollection = web.ContentTypes;
                    clientContext.Load(contentTypeCollection, contentType => contentType.Include(thisContentType => thisContentType.Name).Where(currContentType => currContentType.Group == ServiceConstantStrings.OneDriveContentTypeGroup));
                    clientContext.ExecuteQuery();
                    selectedContentTypeCollection = GetContentTypeList(contentTypesNames, contentTypeCollection.ToList());
                }
            }
            catch (Exception exception)
            {
                ProvisionHelperFunctions.DeleteMatter(requestObject, client, matter);
                Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
            }

            return(selectedContentTypeCollection);
        }