/// <summary> /// Create a custom rule for the content organizer (Without folder auto creation) /// </summary> /// <param name="web">The web</param> /// <param name="ruleName">The rule name</param> /// <param name="ruleDescription">The rule description</param> /// <param name="contentType">The content type name</param> /// <param name="conditionXml">Conditions in XML</param> /// <param name="priority">Rule priority</param> /// <param name="routeToExternalLocation">Route to external location</param> /// <param name="targetPath">The target path</param> /// <param name="customerRouterName">Custom router name</param> public void CreateCustomRule( SPWeb web, string ruleName, string ruleDescription, string contentType, string conditionXml, int priority, bool routeToExternalLocation, string targetPath, string customerRouterName) { var organizerRule = new EcmDocumentRouterRule(web) { Name = ruleName, Description = ruleDescription, ContentTypeString = contentType, ConditionsString = conditionXml, TargetPath = targetPath, RouteToExternalLocation = routeToExternalLocation, Enabled = true, Priority = priority.ToString(CultureInfo.InvariantCulture), CustomRouter = customerRouterName, }; // Create the rule organizerRule.Update(); }
/// <summary> /// Create a custom rule for the content organizer (Without folder auto creation) /// </summary> /// <param name="web">The web</param> /// <param name="ruleName">The rule name</param> /// <param name="ruleDescription">The rule description</param> /// <param name="contentType">The content type name</param> /// <param name="conditionXml">Conditions in XML</param> /// <param name="priority">Rule priority</param> /// <param name="routeToExternalLocation">Route to external location</param> /// <param name="targetPath">The target path</param> /// <param name="customerRouterName">Custom router name</param> public void CreateCustomRule( SPWeb web, string ruleName, string ruleDescription, string contentType, string conditionXml, int priority, bool routeToExternalLocation, string targetPath, string customerRouterName) { var organizerRule = new EcmDocumentRouterRule(web) { Name = ruleName, Description = ruleDescription, ContentTypeString = contentType, ConditionsString = conditionXml, TargetPath = targetPath, RouteToExternalLocation = routeToExternalLocation, Enabled = true, Priority = priority.ToString(CultureInfo.InvariantCulture), CustomRouter = customerRouterName, }; // Create the rule organizerRule.Update(); }
/// <summary> /// Adds the new rule. /// </summary> /// <param name="url">The URL.</param> /// <param name="name">The name.</param> /// <param name="description">The description.</param> /// <param name="libraryName">The library.</param> /// <param name="relativeFolderUrl">The relative folder URL.</param> /// <param name="contentTypeName">Name of the content type.</param> /// <param name="conditionFieldId">The condition field id.</param> /// <param name="conditionFieldInternalName">Name of the condition field internal.</param> /// <param name="conditionFieldTitle">The condition field title.</param> /// <param name="conditionOperator">The condition operator.</param> /// <param name="conditionFieldValue">The condition field value.</param> public void AddNewRule( string url, string name, string description, string libraryName, string relativeFolderUrl, string contentTypeName, string conditionFieldId, string conditionFieldInternalName, string conditionFieldTitle, string conditionOperator, string conditionFieldValue) { List <EcmDocumentRouterRule> ruleList = new List <EcmDocumentRouterRule>(); // Build the conditionSettings XML from the constants above. string conditionXml = String.Format( @"<Condition Column=""{0}|{1}|{2}"" Operator=""{3}"" Value=""{4}"" />", conditionFieldId, conditionFieldInternalName, conditionFieldTitle, conditionOperator, conditionFieldValue); string conditionsXml = String.Format("<Conditions>{0}</Conditions>", conditionXml); using (SPSite spSite = new SPSite(url)) using (SPWeb spWeb = spSite.OpenWeb()) { EcmDocumentRoutingWeb edrw = new EcmDocumentRoutingWeb(spWeb); SPContentType ruleContentType = spWeb.ContentTypes[contentTypeName]; SPList ruleLibrary = spWeb.Lists[libraryName]; if (ruleLibrary.ContentTypes.BestMatch(ruleContentType.Id) == null) { throw new ArgumentException(String.Format("Ensure that the library {0} contains content type {1} before creating the rule", libraryName, contentTypeName)); } // Create a blank rule. Configure the rule.. EcmDocumentRouterRule edrRule = new EcmDocumentRouterRule(spWeb) { Name = name, Description = description, ContentTypeString = ruleContentType.Name, RouteToExternalLocation = false, Priority = "5", TargetPath = spWeb.GetFolder(url + relativeFolderUrl).ServerRelativeUrl, ConditionsString = conditionsXml }; // Update the rule and commit changes. edrRule.Update(); ruleList.Add(edrRule); } }
public void CreateAutofolder(IContentOrganizerRuleCreationData data, SPContentType ruleContentType, EcmDocumentRouterRule organizeDocument) { // Ensure the SPField for the autofolder property TaxonomyField autoFolderField = ruleContentType.Fields[data.AutoFolderPropertyName] as TaxonomyField; if (autoFolderField == null) throw new ArgumentException(String.Format("The field {0} is not a valid Taxonomy Field", data.AutoFolderPropertyName)); // Get a handle to the rule auto folder settings. DocumentRouterAutoFolderSettings autoFolderSettings = organizeDocument.AutoFolderSettings; // Configure AutoFolderSettings for this rule based on the Taxonomy field. autoFolderSettings.AutoFolderPropertyName = autoFolderField.Title; autoFolderSettings.AutoFolderPropertyInternalName = autoFolderField.InternalName; autoFolderSettings.AutoFolderPropertyId = autoFolderField.Id; // Term store Id required to get the value of the field from the document. Required for TaxonomyField types. autoFolderSettings.TaxTermStoreId = autoFolderField.SspId; // Set a format for the name of the folder. autoFolderSettings.AutoFolderFolderNameFormat = data.AutoFolderNameFormat; // Enabled automatic folder creation for values of the field. autoFolderSettings.Enabled = true; }
protected void createRuleButton_Click(object sender, EventArgs e) { SPWeb currentWeb = SPContext.Current.Web; //We must get the EcmDocumentRoutingWeb object that corresponds to the current SPWeb EcmDocumentRoutingWeb routingWeb = new EcmDocumentRoutingWeb(currentWeb); //Get handles on the Document content type and the Shared Documents list SPContentType contentTypeForRule = currentWeb.ContentTypes["Document"]; SPList listForRule = currentWeb.Lists["Shared Documents"]; SPFolder folderForRule = currentWeb.GetFolder(currentWeb.Url + "/Shared%20Documents/DocumentDestination"); //Check that the content type is included in that library if (listForRule.ContentTypes.BestMatch(contentTypeForRule.Id) == null) { resultsLabel.Text = "The Document content type is not available in the " + "Shared Documents folder so the rule cannot be created"; } else { //Create a rule object EcmDocumentRouterRule newRule = new EcmDocumentRouterRule(currentWeb); //Set the properties newRule.Name = "Move all Documents"; newRule.Description = "This rule was create by C# code."; newRule.ContentTypeString = contentTypeForRule.Name; newRule.RouteToExternalLocation = false; newRule.Priority = "5"; newRule.TargetPath = folderForRule.ServerRelativeUrl; //Commit your changes newRule.Update(); } //Tell the user what happened resultsLabel.Text = "Rule created successfully."; }