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:
1. Open Visual Studio 2010.
2. Go to File => New => Project.
3. Select Console Application from the installed templates.
4. Enter the Name and click on Ok.
5. Add the following Namespaces.
o using Microsoft.SharePoint.Utilities; o using System.Collections.ObjectModel;
6. 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();Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
}Â Â Â Â Â Â Â Â Â Â Â
}Â Â Â Â Â Â Â
}Â Â Â
}
}
7. Build the solution.
8. 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 referhttp://msdn.microsoft.com/en-us/library/ee658367.aspx.
ReadOnlyCollection:
Provides the base class for a generic read-only collection.
Comments