public PolicyCollection MapPolicySearchResultToPolicyCollection(IEnumerable <Policy.Contracts.Models.Policy> policies) { var policyCollection = new PolicyCollection(); foreach (var policy in policies) { policyCollection.Add(policy); } return(policyCollection); }
/// <summary> /// Adds the information rights policies. /// </summary> /// <param name="targetCT">The target content type.</param> /// <param name="sourceCT">The source content type.</param> private void AddInformationRightsPolicies(SPContentType targetCT, SPContentType sourceCT) { #if MOSS // Set information rights policy - must be done after the new content type is added to the collection. using (Policy sourcePolicy = Policy.GetPolicy(sourceCT)) { if (sourcePolicy != null) { PolicyCatalog catalog = new PolicyCatalog(targetCT.ParentWeb.Site); PolicyCollection policyList = catalog.PolicyList; Policy tempPolicy = null; try { tempPolicy = policyList[sourcePolicy.Id]; if (tempPolicy == null) { XmlDocument exportedSourcePolicy = sourcePolicy.Export(); try { Logger.Write("Progress: Adding policy '{0}' to content type...", sourcePolicy.Name); PolicyCollection.Add(targetCT.ParentWeb.Site, exportedSourcePolicy.OuterXml); } catch (Exception ex) { if (ex is NullReferenceException || ex is SEHException) { throw; } // Policy already exists Logger.WriteException(new System.Management.Automation.ErrorRecord(new SPException("An error occured creating the information rights policy: {0}", ex), null, System.Management.Automation.ErrorCategory.NotSpecified, exportedSourcePolicy)); } } Logger.Write("Progress: Associating content type with policy '{0}'...", sourcePolicy.Name); // Associate the policy with the content type. Policy.CreatePolicy(targetCT, sourcePolicy); } finally { if (tempPolicy != null) { tempPolicy.Dispose(); } } } targetCT.Update(); } #endif }