Changing MasterPage programmatically for site collection and sub-sites

using System; using System.Collections.Generic; using System.Text; using Microsoft.SharePoint; namespace CustomMaster { public class ChangeMaster : Microsoft.SharePoint.SPFeatureReceiver {   public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWeb CurrentWeb = properties.Feature.Parent as SPWeb; CurrentWeb.MasterUrl = CurrentWeb.Site.RootWeb.ServerRelativeUrl + “/_catalogs/masterpage/MyDefault.master”; CurrentWeb.CustomMasterUrl = CurrentWeb.Site.RootWeb.ServerRelativeUrl + “/_catalogs/masterpage/custom.master”; CurrentWeb.Update(); foreach (SPWeb subweb in Web.GetSubwebsForCurrentUser()) { ChangeMasterPage(subweb, pstrMasterURL, pstrCustomURL); } CurrentWeb.Dispose(); } void ChangeMasterPage(SPWeb…

1

How To : Set calculated field to read-only using Object Model

(A) Create an EventHandler using the ClassLibraryTemplate in the visual Studio 2005. using Microsoft.SharePoint; public class [ClassName] : SPListEventReceiver { public override void FieldUpdating(SPListEventProperties properties) { properties.ErrorMessage = “You can’t changed the column.”; properties.Cancel = true; } } (B) Register the Event Handler using the following Code. // http://tangov39:47242/sites/TestCase/ is the site URL. SPSite collection…

1