Well, I guess you might have discovered as of now that, there is no direct property/field in the Web class which can give you all the information about the theme of your site. SO to get the theme info, you need to know what are the components that a SharePoint site’s theme consist of.
- MasterPage
- CustomMasterPage
- Theme
- Background-Image
- Font
So to know the site current theme using CSOM you need to get the List, Composed Looks, for the current site. Composed Looks will have various items, each of them are a different theme that can be applied to the current site. One of the items it has is, Current. It is this ListItem, which contains the current site theme info. You need to query this item to get the current theme details of a site.
ClientContext ctx = new ClientContext(weburl); ctx.Credentials = new SharePointOnlineCredentials(userName, passWord); SP.List list = ctx.Web.Lists.GetByTitle("Composed Looks"); ctx.Load(list); CamlQuery cQuery = new CamlQuery(); ListItemCollection ltItemCollection = list.GetItems(cQuery); //Load only the required fields ctx.Load(ltItemCollection, w => w.Include( p => p.DisplayName, p => p.FieldValuesAsText["FontSchemeUrl"], p => p.FieldValuesAsText["ImageUrl"], p => p.FieldValuesAsText["ThemeUrl"])); ctx.Load(ctx.Web, w => w.MasterUrl, w => w.CustomMasterUrl); ctx.ExecuteQuery(); ListItem ltItemTemp = ltItemCollection.FirstOrDefault(p => p.DisplayName == "Current");
So, finally, you’ll have the following:-
MasterPage | ctx.Web.MasterUrl |
CustomMasterPage | ctx.Web.CustomMasterUrl |
Theme | ltItemTemp.FieldValuesAsText[“ThemeUrl”] |
Background-Image | ltItemTemp.FieldValuesAsText[“ImageUrl”] |
Font | ltItemTemp.FieldValuesAsText[“FontSchemeUrl”] |
To apply a new theme, check my next blog at, https://realmpksharepoint.wordpress.com/2014/02/24/apply-a-new-theme-to-a-sharepoint-site-using-client-object-model-c/