Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@asadrefai
Created July 27, 2015 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asadrefai/b0c90c0cbf1466e1066e to your computer and use it in GitHub Desktop.
Save asadrefai/b0c90c0cbf1466e1066e to your computer and use it in GitHub Desktop.
Create content organizer rule using CSOM c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
namespace RecordCentreRule
{
class Program
{
static void Main(string[] args)
{
var targetSite = new Uri("https://YourSite.sharepoint.com");
var login = "SomeOne@SharePoint.onmicrosoft.com";
var password = "YourPassword";
var securePassword = new SecureString();
foreach (char c in password)
{
securePassword.AppendChar(c);
}
var onlineCredentials = new SharePointOnlineCredentials(login, securePassword);
using (ClientContext clientCtx = new ClientContext(targetSite))
{
clientCtx.Credentials = onlineCredentials;
Web web = clientCtx.Web;
List routingRulesList = web.Lists.GetByTitle("Content Organizer Rules");
clientCtx.Load(routingRulesList);
clientCtx.ExecuteQuery();
ListItemCreationInformation routingRuleInfo = new ListItemCreationInformation();
ListItem routingRule = routingRulesList.AddItem(routingRuleInfo);
routingRule["Title"] = "From Console";
routingRule["RoutingRuleName"] = "From Console";
routingRule["RoutingRuleDescription"] = "From Console";
routingRule["RoutingPriority"] = 1;
routingRule["RoutingEnabled"] = true;
routingRule["RoutingContentType"] = "Your Content Type Name";
routingRule["RoutingContentTypeInternal"] = "0x000000000000000000000000000000000000000000000000000000|Your Content Type Name";
routingRule["RoutingConditions"] = "<Conditions><Condition Column=\"xxxx-xxx-xxx-xxx-xxxxx|Column|Column Name\" Operator=\"EqualsOrIsAChildOf\" Value=\"1;#WhatEver|xxxx-xxx-xxx-xxx-xxxx\" /></Conditions>";
routingRule["RoutingConditionProperties"] = "Column Name on which you need condition";
routingRule["RoutingAliases"] = "Your Content Type Name";
routingRule["RoutingTargetLibrary"] = "Target Library";
routingRule["RoutingTargetFolder"] = "";
routingRule["RoutingTargetPath"] = "/sites/YourSite/Target Library";
routingRule["RoutingAutoFolderProp"] = "Folder Property";
routingRule["RoutingAutoFolderSettings"] = "<AutoFolder><Properties><Property Name=\"AutoFolderEnabled\" Value=\"True\" /><Property Name=\"AutoFolderPropertyName\" Value=\"Folder Property\" /><Property Name=\"AutoFolderPropertyInternalName\" Value=\"WhatEver\" /><Property Name=\"AutoFolderPropertyID\" Value=\"xxxx-xxxx-xxx-xxx-xxxx\" /><Property Name=\"AutoFolderPropertyFormat\" Value=\"%1 - %2\" /><Property Name=\"AutoFolderPropertyTypeAsString\" Value=\"TaxonomyFieldType\" /><Property Name=\"AutoFolderPropertyTermStore\" Value=\"xxxx-xxx-xxx-xxx-xxxxx\" /></Properties></AutoFolder>";
routingRule["RoutingCustomRouter"] = "";
routingRule["RoutingRuleExternal"] = false;
routingRule.Update();
clientCtx.ExecuteQuery();
Console.WriteLine("Rule created successfully");
Console.Read();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment