Branding / Changing site logo via custom code (in SharePoint 2013 Online / Office 365)

Hi everybody,

I'd like to change the site logo for the whole site collection via code.

Background: I'm creating and setting up site collections via code and it's required to also change the site logo to my customer's logo. In SharePoint Online it's not possible to create a "global" master page, etc.

I already searched the web for a solution with no success. Could you please point me in the right direction, how I can accomplish that with the client side object model (CSOM)?

I know that it's possible to change the logo manually via
site settings =>Title, description, and logo,
but I need to do it via code.

Many thanks in advance and best regards

Christian

January 10th, 2014 2:00pm

Hi,

For your requirement, a workaround is that we can create another master page with different Site Logo, then modify the masterUrl and customMasterUrl property to change the master page of the current site to this custom master page.

A code demo about this for your reference:

function ChangeMasterPage() 
{
    var context;
    var web;
    var strMasterPageUrl = '/_catalogs/masterpage/my_custom.master';
    context = new SP.ClientContext.get_current();
    web = context.get_web();
    //Updage Site Master Page
    web.set_customMasterUrl(strMasterPageUrl);    
    //Updage System Master Page
    web.set_masterUrl(strMasterPageUrl);    
    web.update();
    context.executeQueryAsync(function () 
    {
        alert("Master Page has been set to \n" + strMasterPageUrl);
    }, function (sender, args) {

        alert("Error: " + args.get_message());

    });
}

More details can be found in this link:

SharePoint Online - Changing Master Page through CSOM

https://www.nothingbutsharepoint.com/sites/devwiki/articles/pages/sharepoint-online-changing-master-page-through-csom.aspx

Best regards

Free Windows Admin Tool Kit Click here and download it now
January 13th, 2014 4:21am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics