private static void EnsureUniqueContentTypeOrder(SPFolder folder, FolderInfo folderInfo) { if (folderInfo.UniqueContentTypeOrder != null && folderInfo.UniqueContentTypeOrder.Count > 0) { SPContentTypeCollection listContentTypes = folder.ParentWeb.Lists[folder.ParentListId].ContentTypes; IList <SPContentType> uniqueOrder = new List <SPContentType>(); foreach (ContentTypeInfo needToEnsureThisCTInfo in folderInfo.UniqueContentTypeOrder) { var foundRealCT = listContentTypes[needToEnsureThisCTInfo.ContentTypeId]; if (foundRealCT == null) { // Failed to find CT with direct ID lookup: now let's assume that we were given site collection CT IDs as // input and that we need to inspect the list CTs' parents to find a match. foreach (var listCT in listContentTypes.Cast <SPContentType>()) { if (listCT.Id.Parent == needToEnsureThisCTInfo.ContentTypeId) { foundRealCT = listCT; break; } } } uniqueOrder.Add(foundRealCT); } folder.UniqueContentTypeOrder = uniqueOrder; folder.Update(); } }
public static List<Model.ContentType> ToContentTypes(SPContentTypeCollection contentTypes) { return contentTypes.Cast<SPContentType>().Select(ct => new Model.ContentType { Id = ct.Id.ToString(), Name = ct.Name }).ToList(); }
public static List <Model.ContentType> ToContentTypes(SPContentTypeCollection contentTypes) { return(contentTypes.Cast <SPContentType>().Select(ct => new Model.ContentType { Id = ct.Id.ToString(), Name = ct.Name }).ToList()); }
private void GetPublishingTypes(SPList list) { Func <SPContentType, bool> contentgroup = null; if (contentgroup == null) { contentgroup = delegate(SPContentType f) { return(f.Id.Parent == Hemrika.SharePresence.WebSite.ContentTypes.ContentTypeId.PageTemplate); }; } SPContentTypeCollection contentypes = list.ContentTypes; publishingtypes = contentypes.Cast <SPContentType>().Where <SPContentType>(contentgroup); }
private static SPContentType FindContentTypeWithField(SPContentTypeCollection contentTypeCollection, TaxonomyField fieldToSet) { return contentTypeCollection.Cast<SPContentType>().FirstOrDefault(ct => { return ct.Fields.Cast<SPField>().Any(spField => spField.InternalName == fieldToSet.InternalName); }); }
/// <summary> /// Ensures the approval workflow on list. /// </summary> /// <param name="web">The web.</param> /// <param name="list">The list.</param> /// <param name="events">The events.</param> /// <param name="useSamlWorkflow">Whether to use the SAML Approval workflow</param> /// <returns> /// The workflow subscription id /// </returns> /// <exception cref="System.ArgumentNullException"></exception> public static Guid EnsureApprovalWorkflowOnList(SPWeb web, SPList list, List <WorkflowStartEventType> events, bool useSamlWorkflow) { Guid subscriptionId = Guid.Empty; if (list == null) { throw new ArgumentNullException("list"); } // Remove existing 2010 workflow associations SPWorkflowAssociationCollection existingWorkflows = list.WorkflowAssociations; if (existingWorkflows != null) { for (int i = 0; i < existingWorkflows.Count; i++) { list.WorkflowAssociations.Remove(existingWorkflows[i]); } } //SPFeature customWorkflowActivitiesFeature = web.Features[customWorkflowActivitiesFeatureId]; //if (customWorkflowActivitiesFeature == null) //{ // customWorkflowActivitiesFeature = web.Features.Add(customWorkflowActivitiesFeatureId); //} SPFeature customWorkflowFeature = web.Features[customWorkflowFeatureId]; if (customWorkflowFeature == null) { customWorkflowFeature = web.Features.Add(customWorkflowFeatureId); } if (customWorkflowFeature != null) { if (!list.EnableModeration || !list.ForceCheckout) { list.EnableModeration = true; list.ForceCheckout = true; list.EnableVersioning = true; list.Update(); } Dictionary <string, string> workflowPropertyData = GetApprovalWorkflowSettings(web, list.Title); SPList taskList = EnsureWorkflowTaskList(web, "/lists/workflowtasks", string.Empty); SPList historyList = EnsureWorkflowHistoryList(web, "/workflowhistory", string.Empty); if (taskList != null && historyList != null) { bool workflowTaskContentTypeAssociated = false; foreach (SPContentType contentType in taskList.ContentTypes) { if (contentType.Parent.Id.ToString().Equals(ContentTypeWorkflowTaskSharePoint2013, StringComparison.OrdinalIgnoreCase)) { workflowTaskContentTypeAssociated = true; break; } } if (!workflowTaskContentTypeAssociated) { SPContentType wftaskContentType = default(SPContentType); SPContentTypeCollection contentTypes = web.ContentTypes.Count == 0 ? web.Site.RootWeb.ContentTypes : web.ContentTypes; wftaskContentType = contentTypes.Cast <SPContentType>().FirstOrDefault <SPContentType>(c => c.Id.ToString().Equals(ContentTypeWorkflowTaskSharePoint2013, StringComparison.OrdinalIgnoreCase)); if (wftaskContentType != null) { taskList.ContentTypes.Add(wftaskContentType); } } string displayName = ResourcesHelper.GetLocalizedString("workflow_approval_instancename"); Guid workflowDefId = useSamlWorkflow ? approvalSamlWorkflowDefinitionId : approvalWorkflowDefinitionId; subscriptionId = EnsureWorkflowOnList(web, list, workflowDefId, displayName, events, taskList, historyList, workflowPropertyData, false); EnableWorkflowsRunAsAnApp(web); SubscribeToEventReceivers(list, false); } } return(subscriptionId); }