SIGN UP MEMBER LOGIN:    
ARTICLE

Programmatically change the site theme in SharePoint

Posted by Vijai Anand Articles | SharePoint April 26, 2011
In this article we will be seeing how to change the site theme in SharePoint using SharePoint object model.
Reader Level:

In this article we will be seeing how to change the site theme in SharePoint using SharePoint object model.

Go to Site Actions => Site Settings => Look and Feel => Site theme.

ThemeShare1.gif

Programmatically change the site theme:

  • Open Visual Studio 2010.
  • Go to File => New => Project.
  • Select Console Application from the installed templates.
  • Enter the Name and click on Ok.
  • Add the following Namespaces.

    o using Microsoft.SharePoint.Utilities;
    o using System.Collections.ObjectModel;
     
  • Replace Program.cs with the following code.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;
    using System.Xml;
    using Microsoft.SharePoint.Utilities;
    using System.Collections.ObjectModel;

    namespace ChangeTheme
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (SPSite siteCollection = new SPSite("http://serverName:1111/sites/Sample"))
                {
                    using (SPWeb web = siteCollection.OpenWeb())
                    {
                        ThmxTheme theme =ThmxTheme.Open(siteCollection,"_catalogs/theme/Azure.thmx");
                        theme.ApplyTo(web,false);
                        web.Update();
                    }
                }
            }
        }
    }
     

  • Build the solution.

  • Hit F5.

  • Output:

    ThemeShare2.gif

ThmxTheme class:

Represents a Microsoft Office XML theme file. The methods and properties of this class enable read and write operations on the theme name, the color list, and the font list. For more information refer http://msdn.microsoft.com/en-us/library/ee658367.aspx.

ThmxTheme.ApplyTo Method (SPWeb, Boolean):

Applies the current theme to the given web. . For more information refer http://msdn.microsoft.com/en-us/library/ee659982.aspx




 

Login to add your contents and source code to this article
share this article :
post comment
 

can you please tell me the reason as to why this function doesnt work for a WCF service

Posted by shoeb sayyed Oct 04, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor