Posts

Showing posts with the label CSOM

SharePoint: How can I improve the search relevance of a list item? (How do I use RecordPageClick?)

In order to improve the relevance of a list item, I learnt about RecordClick . Thankfully, I found the following code on Technet  to resolve the problem. I have duplicated it here. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Security; using System.Threading.Tasks; using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.Search; using Microsoft.SharePoint.Client.Search.Query; using System.IO; namespace SPOnlinePageCallback2 {     class Program     {         static void Main(string[] args)         {             using (ClientContext clientContext = new ClientContext("https://xxxxxxx.sharepoint.com/"))             {                 SecureString passWord = new SecureString();                 foreach ...

SharePoint: How do I upload a file structure to a document library?

My current project uses a custom 'style library' document library. The deployment process needed to replicate the files and file structure from the disk in the target library. I used CSOM and Powershell to solve the problem. I created a 'Common' dll that contains the methods I needed: 1. CreateFolder (to create a folder structure) 2. UploadFile (to load the file).     public static class FileHelper     {         public static Folder CreateFolder(Web web, string listTitle, string fullFolderPath)         {             if (string.IsNullOrEmpty(fullFolderPath))                 throw new ArgumentNullException("fullFolderPath");             var list = web.Lists.GetByTitle(listTitle);             return CreateFolderInternal(web, list.RootFolder, fullFolderPath);         }...

SharePoint Online: How do I extract list changes with PowerShell?

Import-Module 'C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell' -DisableNameChecking $loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") $loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") $webUrl = "https://mysite.sharepoint.com/" $username = "richard.leeman@mydomain.onmicrosoft.com" $password = Read-Host -Prompt "Password for $username" -AsSecureString $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl) $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) $web = $ctx.Web $webs = $web.Webs $lists = $web.Lists $ctx.Load($lists) $ctx.Load($webs) $ctx.Load($web) $ctx.ExecuteQuery() $list = $lists| Where-Object { $_.Title -eq "My Documents"} $dt = Get-Date $dtUTC = $dt.ToUniversalTime() $changeQ...

SharePoint Online: How do I configure the Site Collection Audit Settings from CSOM?

My current project requires that the Site Collection Audit Settings be provisioned with every new OneDrive for Business site. The problem is that there is not existing API (in CSOM or PowerShell) to set these values. Problem? Yes. Insurmountable? No. I was pointed in the direction of this  fantastic blog. The basic idea behind the code is to replicate the 'POST' event that is created by using the UI. The code is magnificent but (as is continually stressed in the video) is not supported by Microsoft.  This does not mean that is will not work, it just means that should the name of the underlying fields change, the code will fail unceremoniously. Anyway, back to the solution.  Firstly, enable the 'Reporting' Site Collection feature. The feature Guid is "7094bd89-2cfe-490a-8c7e-fbace37b4a34" and should be activated as a FARM level feature Secondly, here is my add-in code to the set values. using System.Globalization; namespace Contoso.Remote...

SharePoint Online: How do I set the Web.AlternateCSS property in CSOM?

The properties are only exposed in the '16' (SharePoint Online) version of the client side dlls. You will need to change your references to point to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll and C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll

SharePoint Online: How do I set the IRM settings for a Document Library in PowerShell?

I have used the CSOM approach to resolve the problem. Here  is an excellent post outlining the available methods that I based this script on. Import-Module 'C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell' -DisableNameChecking $loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") $loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") $webUrl = "https://mytestsite.sharepoint.com/mysubsite" $username = "richard.leeman@mysharepointonlinelogin.com" $password = Read-Host -Prompt "Password for $username" -AsSecureString $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl) $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) $web = $ctx.Web $lists = $web.Lists $ctx.Load($lists) $ctx.Load($web) $ctx.ExecuteQuery() $li...