In this article we will be seeing how to get all the available SharePoint site
themes using SharePoint object model.
Go to Site Actions => Site Settings => Look and Feel => Site theme.

Programmatically get all the available site themes:
- 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 Themes
{
class Program
{
static void Main(string[] args)
{
using (SPSite siteCollection = new SPSite("http://serverName:1111/sites/sample"))
{
using (SPWeb web = siteCollection.OpenWeb())
{
ReadOnlyCollection<ThmxTheme> themes = ThmxTheme.GetManagedThemes(siteCollection);
foreach (ThmxTheme theme in themes)
{
Console.WriteLine(theme.Name);
}
Console.ReadLine();
}
}
}
}
}
-
Build the solution.
-
Hit F5.
-
Output:

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.
ReadOnlyCollection:
Provides the base class for a generic read-only collection.

hypper funPosted Apr 24, 2012, 8:26 AM
Hi i have a problem with colors of my custom webpart how to get colors from theme selected in a site sharepoint foundation 2010 and apply to my custom webpart using c# pleas help,
shoeb sayyedPosted Oct 4, 2011, 2:38 AM
I am trying to apply a theme to a sharepoint site. my method is as follows : public void ApplyCustomeTheme(string url, string themeName) { using (SPSite oSite = new SPSite(url)) { using (SPWeb oWeb = oSite.OpenWeb()) { System.Collections.ObjectModel.ReadOnlyCollection<ThmxTheme> oThemes = ThmxTheme.GetManagedThemes(oSite); // list out all themes of this particular site foreach (ThmxTheme oTheme in oThemes) { // Apply my custom theme to the current website if (oTheme.Name == themeName) { ThmxTheme.SetThemeUrlForWeb(oWeb, oTheme.ServerRelativeUrl); } } } } } but when i try to run the WCF client i get the following error: Could not load file or assembly 'Microsoft.SharePoint.Search' or one of its dependencies. An attempt was made to load a program with an incorrect format. I have included the 'Microsoft.SharePoint.Search' dll in the References. Can some one please explain me what is causing this ?. Is it because of serialization ? Can i get a solution on this ?