How To Change The Look Of SharePoint Using CSOM

In SharePoint, we can manually change the look and feel of a site collection. Let's see how.
 
Navigate to Site Settings -> Look and Feel -> Change the look.
Select the template that you want to keep.
 
To change the SharePoint look programmatically, first, we have to get the Theme URL, Image URL, and the Font Scheme URL of templates. We can get all the details from the Composed Looks list which can be seen by going to the Site URL and adding the following part into it - 
 
/_catalogs/design/AllItems.aspx
 
The following image shows a Composed Looks list which contains different templates with different Theme URLs, Image URLs, and Font Scheme URLs.
 
How To Change The Look Of SharePoint Using CSOM
 
We are using some of the URLs from here. Now, our code looks like the following.
  1. using System;  
  2. using System.Net;  
  3. using Microsoft.SharePoint.Client;  
  4. namespace ApplyTheme {  
  5.     class Program {  
  6.         static void Main(string[] args) {  
  7.             ClientContext ctx = new ClientContext("http://portal/sites/site1");  
  8.             Web web = ctx.Web;  
  9.             NetworkCredential cred = new NetworkCredential("[email protected]""password");  
  10.             ctx.Credentials = cred;  
  11.             ctx.Load(web);  
  12.             ctx.ExecuteQuery();  
  13.             var themeUrl = web.ServerRelativeUrl + "/_catalogs/theme/15/palette008.spcolor";  
  14.             var fontSchemeUrl = web.ServerRelativeUrl + "/_catalogs/theme/15/fontscheme003.spfont";  
  15.             var imageUrl = web.ServerRelativeUrl + "/_layouts/15/images/image_bg008.jpg";  
  16.             web.ApplyTheme(themeUrl, fontSchemeUrl, imageUrl, true);  
  17.             web.Update();  
  18.             ctx.ExecuteQuery();  
  19.         }  
  20.     }  
  21. }   
How To Change The Look Of SharePoint Using CSOM 
 
Result
 
I have changed the theme of my SharePoint site to Sketch Template type. After the code has executed successfully, you can see that the Site Collection has a new look.