Programmatically remove the theme from the SharePoint web

In this article we will be seeing how to remove the theme from the SharePoint web using SharePoint object model.


In this article we will be seeing how to remove the theme from the SharePoint web using SharePoint object model.

The current theme will be changed to Default(No theme).

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

RemoveShare1.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 RemoveTheme
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (SPSite siteCollection = new SPSite("http://serverName:1111/sites/Sample"))
                {
                    using (SPWeb web = siteCollection.OpenWeb())
                    {
                        ThmxTheme.RemoveThemeFromWeb(web,false);                   
                        web.Update();
                    }
                }
            }
        }
    }

     
  • Build the solution.
  • Hit F5.
  • Output:

    RemoveShare2.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.RemoveThemeFromWeb Method:

Sets the theme on the web to none. For more information refer http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.thmxtheme.removethemefromweb.aspx.