Pages

How to Change SharePoint Online masterpage from Seattle to Oslo using CSOM

using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UpdateMasterPage
{
public partial class UpdateMasterPage: System.Windows.Forms.Form
{
    public UpdateMasterPage ()
    {
        InitializeComponent();
    }


    private SecureString ConvertToSecureString(string password)
    {
        if (password == null)
            throw new ArgumentNullException("password");

        var securePassword = new SecureString();

        foreach (char c in password)
            securePassword.AppendChar(c);

        securePassword.MakeReadOnly();
        return securePassword;
    }
    private void button1_Click(object sender, EventArgs e)
    {
        Microsoft.SharePoint.Client.ClientContext cc = new Microsoft.SharePoint.Client.ClientContext("https://Gowtha.pnpdemo.com/");
        SecureString secstring = ConvertToSecureString(“********”);
        SharePointOnlineCredentials creds = new SharePointOnlineCredentials("gowtham@pnp.onmicrosoft.com", secstring);


        // The SharePoint web at the URL.
        Web web = cc.Web;

        // We want to retrieve the web's properties.
        cc.Load(web);

        // Execute the query to the server.
        cc.ExecuteQuery();

        var a = web.Title; // For debug checks.
        var master = web.CustomMasterUrl; // For debug checks.
        web.CustomMasterUrl = "/_catalogs/masterpage/seattle.master"; // Or the original page desired.
        web.MasterUrl = "/_catalogs/masterpage/seattle.master";
        web.Update();
        // Execute the query to server.
        cc.ExecuteQuery();
    }
}




Gowtham

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments:

Post a Comment