only My site

Tuesday, June 4, 2013

Apply Theme for Publishing site


public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
   ApplyTheme(properties);
}
/// <summary>
/// Sets master page and css properties for the site collection
/// </summary>
/// <param name="properties"></param>
private void ApplyTheme(SPFeatureReceiverProperties properties)
{
SPSite site = (SPSite)properties.Feature.Parent;
if (site != null)
{
// System Master Page
Uri masterUri = new Uri(site.RootWeb.Url + "/_catalogs/masterpage/v4.master");
site.RootWeb.MasterUrl = masterUri.AbsolutePath;
// Publishing Master Page
Uri customMasterUri = new Uri(site.RootWeb.Url + "/_catalogs/masterpage/mycustom.master");
site.RootWeb.CustomMasterUrl = customMasterUri.AbsolutePath;
//logo and css
site.RootWeb.SiteLogoUrl = "/_layouts/MyProjectName/Images/mycustomlogo.jpg";
site.RootWeb.AlternateCssUrl = "/Style Library/MyProjectName/css/mycustomcss.css";
site.RootWeb.Update();
}
}

No comments: