Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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");
- ListItem itm = routingRulesList.GetItemById(1);
- clientCtx.Load(web);
- clientCtx.Load(routingRulesList);
- clientCtx.Load(itm);
- clientCtx.ExecuteQuery();
- Console.WriteLine("Title: " + itm["Title"] + "n");
- Console.WriteLine("RoutingConditions: " + itm["RoutingConditions"] + "n");
- Console.WriteLine("RoutingConditionProperties: " + itm["RoutingConditionProperties"] + "n");
- Console.WriteLine("RoutingContentType: " + itm["RoutingContentType"] + "n");
- Console.WriteLine("RoutingContentTypeInternal: " + itm["RoutingContentTypeInternal"] + "n");
- Console.WriteLine("RoutingConditions: " + itm["RoutingConditions"] + "n");
- Console.WriteLine("RoutingConditionProperties: " + itm["RoutingConditionProperties"] + "n");
- Console.WriteLine("RoutingAliases: " + itm["RoutingAliases"] + "n");
- Console.WriteLine("RoutingTargetLibrary: " + itm["RoutingTargetLibrary"] + "n");
- Console.WriteLine("RoutingTargetFolder: " + itm["RoutingTargetFolder"] + "n");
- Console.WriteLine("RoutingTargetPath: " + itm["RoutingTargetPath"] + "n");
- Console.WriteLine("RoutingAutoFolderProp: " + itm["RoutingAutoFolderProp"] + "n");
- Console.WriteLine("RoutingAutoFolderSettings: " + itm["RoutingAutoFolderSettings"] + "n");
- Console.WriteLine("RoutingCustomRouter: " + itm["RoutingCustomRouter"] + "n");
- Console.WriteLine("RoutingRuleExternal: " + itm["RoutingRuleExternal"] + "n");
- Console.Read();
- }
- }
- }
- }
- # replace these details (also consider using Get-Credential to enter password securely as script runs)..
- $username = "SomeOne@SharePoint.onmicrosoft.com"
- $password = "YourPassword"
- $url = "https://YourSite.sharepoint.com"
- $securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
- # the path here may need to change if you used e.g. C:Lib..
- Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- # connect/authenticate to SharePoint Online and get ClientContext object..
- $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
- $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
- $clientContext.Credentials = $credentials
- if (!$clientContext.ServerObjectIsNull.Value)
- {
- Write-Host "Connected to SharePoint Online site: '$Url'" -ForegroundColor Green
- $web = $clientContext.Site.RootWeb
- $listRoutingRules = $web.Lists.GetByTitle("Content Organizer Rules")
- $item = $listRoutingRules.GetItemById(1)
- $clientContext.Load($listRoutingRules)
- $clientContext.Load($item)
- $clientContext.ExecuteQuery()
- Write-Host "Title: " $item["Title"]
- Write-Host "RoutingConditions: " $item["RoutingConditions"]
- Write-Host "RoutingConditionProperties: " $item["RoutingConditionProperties"]
- Write-Host "RoutingContentType: " $item["RoutingContentType"]
- Write-Host "RoutingContentTypeInternal: " $item["RoutingContentTypeInternal"]
- Write-Host "RoutingConditions: " $item["RoutingConditions"]
- Write-Host "RoutingConditionProperties: " $item["RoutingConditionProperties"]
- Write-Host "RoutingAliases: " $item["RoutingAliases"]
- Write-Host "RoutingTargetLibrary: " $item["RoutingTargetLibrary"]
- Write-Host "RoutingTargetFolder: " $item["RoutingTargetFolder"]
- Write-Host "RoutingTargetPath: " $item["RoutingTargetPath"]
- Write-Host "RoutingAutoFolderProp: " $item["RoutingAutoFolderProp"]
- Write-Host "RoutingAutoFolderSettings: " $item["RoutingAutoFolderSettings"]
- Write-Host "RoutingCustomRouter: " $item["RoutingCustomRouter"]
- Write-Host "RoutingRuleExternal: " $item["RoutingRuleExternal"]
- }
- 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();
- }
- }
- }
- }
- # replace these details (also consider using Get-Credential to enter password securely as script runs)..
- $username = "SomeOne@SharePoint.onmicrosoft.com"
- $password = "YourPassword"
- $url = "https://YourSite.sharepoint.com"
- $securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
- # the path here may need to change if you used e.g. C:Lib..
- Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- # connect/authenticate to SharePoint Online and get ClientContext object..
- $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
- $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
- $clientContext.Credentials = $credentials
- if (!$clientContext.ServerObjectIsNull.Value)
- {
- Write-Host "Connected to SharePoint Online site: '$Url'" -ForegroundColor Green
- $web = $clientContext.Site.RootWeb
- $listRoutingRules = $web.Lists.GetByTitle("Content Organizer Rules")#RoutingRules
- $clientContext.Load($listRoutingRules)
- $clientContext.ExecuteQuery()
- #Add an item to the list
- $ListItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
- $Item1 = $listRoutingRules.AddItem($ListItemInfo)
- $Item1["Title"] = "Asad Test Rule"
- $Item1["RoutingRuleName"] = "Asad Test Rule"
- $Item1["RoutingRuleDescription"] = "Asad Test Rule"
- $Item1["RoutingPriority"] = 1
- $Item1["RoutingEnabled"] = $true
- $Item1["RoutingContentType"] = "Your Content Type Name"
- $Item1["RoutingContentTypeInternal"] = "0x000000000000000000000000000000000000000000000000000000|Your Content Type Name"
- $Item1["RoutingConditions"] = '<Conditions><Condition Column="xxxx-xxx-xxx-xxx-xxxxxx|ColumnName|Column Name" Operator="EqualsOrIsAChildOf" Value="1;#Value|xxxx-xxx-xxx-xxx-xxxxxx" /></Conditions>'
- $Item1["RoutingConditionProperties"] = "Condition Property"
- $Item1["RoutingAliases"] = "Alias Name"
- $Item1["RoutingTargetLibrary"] = "Target Library"
- $Item1["RoutingTargetFolder"] = ""
- $Item1["RoutingTargetPath"] = "/sites/YourSite/Target Library"
- $Item1["RoutingAutoFolderProp"] = "Folder Property"
- $Item1["RoutingAutoFolderSettings"] = '<AutoFolder><Properties><Property Name="AutoFolderEnabled" Value="True" /><Property Name="AutoFolderPropertyName" Value="Your Value" /><Property Name="AutoFolderPropertyInternalName" Value="YourValue" /><Property Name="AutoFolderPropertyID" Value="xxxx-xxx-xxx-xx-xxxxx" /><Property Name="AutoFolderPropertyFormat" Value="%1 - %2" /><Property Name="AutoFolderPropertyTypeAsString" Value="TaxonomyFieldType" /><Property Name="AutoFolderPropertyTermStore" Value="xxxx-xxx-xxx-xxx-xxxxxx" /></Properties></AutoFolder>'
- $Item1["RoutingCustomRouter"] = ""
- $Item1["RoutingRuleExternal"] = $false
- $Item1.Update()
- $clientContext.ExecuteQuery()
- Write-Host "Rule created successfully" -ForegroundColor Green
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement