Monday, May 20, 2013

Set Master page when new sub site is created

Step 1:
Create Master page using following URL
http://msdn.microsoft.com/en-us/library/gg447066.aspx

Step 2:
Create Event receiver(right click -> Add New Item-> Event Receiver)

Step 3:
Choose Web events as Event Receiver type
and select "A Site was provisioned"















Step 4:
    public override void WebProvisioned(SPWebEventProperties properties)
        {
            SPWeb topLevelSite = properties.Web;
            string WebAppRelativePath = topLevelSite.Url;
            if (!WebAppRelativePath.EndsWith("/"))
            {
                WebAppRelativePath += "/";
            }

            topLevelSite.MasterUrl = WebAppRelativePath +
                                          "_catalogs/masterpage/Muthuvel2SpCustomMaster.master";
            topLevelSite.CustomMasterUrl = WebAppRelativePath +
                                   "_catalogs/masterpage/Muthuvel2SpCustomMaster.master";
            topLevelSite.UIVersion = 4;
            topLevelSite.Update();
      }

Step 5:
Deploy the application.

Step 6:
Go the the application and create new site. The master page applied for the newly created site.

REF URL: http://www.sharepointkings.com/2012/04/implement-sharepoint-2010-site-event.html


No comments: