ARTICLE

How to set a master page to the site in SharePoint 2010 using powershell

Posted by Vijai Anand Articles | SharePoint 2010 March 01, 2011
In this article we will be seeing how to set the master page to the site in SharePoint 2010 using powershell and using console application.
Reader Level:

In this article we will be seeing how to set the master page to the site in SharePoint 2010 using powershell and using console application.

In this article

  • Set a master page to the site in SharePoint 2010 using console application
  • Set a master page to the site in SharePoint 2010 using powershell

Steps Involved:

  • Open Visual Studio 2010.
  • Create a console application.
  • Add the following reference.

    o Microsoft.SharePoint.dll;
     
  • Add the following namespace.

    o Using Microsoft.SharePoint;

Set a master page to the site in SharePoint 2010 using console application

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace CustomPermissionLevel
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://servername:2020/"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    Uri masterUri=new Uri (web.Url+"/_catalogs/masterpage/v4.master");
                    web.MasterUrl = masterUri.AbsolutePath;
                    web.CustomMasterUrl=masterUri.AbsolutePath;
                    web.Update();
                }
            }
        }
    }
}


Set a master page to the site in SharePoint 2010 using powershell script

$customMasterPage="/_catalogs/masterpage/v4.master"
$site=get-SpSite "http://servername:2020/"
$web=$site.RootWeb
$masterUri=New-Object System.Uri($web.Url+$customMasterPage)
$web.MasterUrl=$masterUri.AbsolutePath
$web.CustomMasterUrl=$masterUri.AbsolutePath
$web.Update()
$web.Dispose()
$site.Dispose()


For creating master page using visual studio 2010 refer http://www.c-sharpcorner.com/UploadFile/anavijai/5224/

Login to add your contents and source code to this article
post comment
     
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter