Getting the Current Theme in .NET

Generator QR Code 2d barcode in .NET Getting the Current Theme

Getting the Current Theme
Scanning QR Code In .NET
Using Barcode Control SDK for .NET Control to generate, create, read, scan barcode image in .NET framework applications.
Making QR-Code In .NET Framework
Using Barcode drawer for .NET Control to generate, create QR Code JIS X 0510 image in Visual Studio .NET applications.
Let s start with retrieving a site s current theme First, use the Get-SPWeb cmdlet to bind to the site
Denso QR Bar Code Scanner In VS .NET
Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
Making Barcode In .NET
Using Barcode drawer for .NET Control to generate, create barcode image in Visual Studio .NET applications.
PS > $spWeb = Get-SPWeb -Identity http://nimaintranet
Recognize Barcode In .NET Framework
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
QR Code Printer In C#.NET
Using Barcode creator for VS .NET Control to generate, create QR Code image in .NET framework applications.
The SPWeb object is then used with the static GetThemeUrlForWeb method provided by the MicrosoftSharePointUtilitiesThmxTheme class and stored in the variable theme
Creating QR Code 2d Barcode In VS .NET
Using Barcode generation for ASP.NET Control to generate, create QR Code ISO/IEC18004 image in ASP.NET applications.
QR-Code Printer In VB.NET
Using Barcode encoder for VS .NET Control to generate, create QR Code image in Visual Studio .NET applications.
PS > $theme = >> [MicrosoftSharePointUtilitiesThmxTheme]::GetThemeUrlForWeb($spWeb)
Barcode Generation In .NET
Using Barcode encoder for .NET Control to generate, create bar code image in .NET framework applications.
Draw Barcode In Visual Studio .NET
Using Barcode generator for Visual Studio .NET Control to generate, create bar code image in VS .NET applications.
If the site uses the default theme, an empty string is returned by this method Otherwise, the method returns a string containing the relative path to the theme Next, we check if the variable contains a value If it does, we use the static Open method provided by the MicrosoftSharePointUtilitiesThmxTheme class This method has six overloads where each one of them accepts two parameters: an SPSite object and a theme URL
Paint EAN-13 Supplement 5 In .NET
Using Barcode encoder for VS .NET Control to generate, create EAN13 image in .NET applications.
Print Leitcode In VS .NET
Using Barcode drawer for Visual Studio .NET Control to generate, create Leitcode image in Visual Studio .NET applications.
PS >> >> >> >> > if (-not([string]::IsNullOrEmpty($theme))) { [MicrosoftSharePointUtilitiesThmxTheme]::Open($spWebSite, $theme) | Format-List -Property @{Name="Theme";Expression={$_Name}}, @{Name="Type";Expression={$_ThemeType}}, @{Name="RelativeUrl";Expression={$_ServerRelativeUrl}},
Decoding Code 39 Full ASCII In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
Generating UPC-A In Java
Using Barcode generation for BIRT Control to generate, create UPC Code image in Eclipse BIRT applications.
13:
Making UPC Symbol In VS .NET
Using Barcode creator for Reporting Service Control to generate, create UPC-A Supplement 5 image in Reporting Service applications.
EAN / UCC - 13 Decoder In .NET
Using Barcode reader for .NET framework Control to read, scan read, scan image in .NET framework applications.
Managing the Look and Feel of Sites
GTIN - 13 Recognizer In VB.NET
Using Barcode decoder for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
Bar Code Creator In Visual Studio .NET
Using Barcode maker for ASP.NET Control to generate, create barcode image in ASP.NET applications.
>> >> >> >> >> PS
Encode Barcode In VB.NET
Using Barcode generator for Visual Studio .NET Control to generate, create bar code image in Visual Studio .NET applications.
Recognize Code 128 Code Set C In C#.NET
Using Barcode reader for .NET Control to read, scan read, scan image in .NET applications.
@{Name="Description";Expression={$_AccessibleDescription}} } else { Write-Host "Default theme is used" } > $spWebDispose()
In this example, we use an if statement to check if the theme variable contains a value If the condition evaluates to True, we use the Open method supported by the ThmxTheme class to retrieve the theme that is currently used on the site, and use the Format-List cmdlet to display specific properties If the variable theme is null or empty, we use the Write-Host cmdlet and return a message Finally, we dispose of the object using the Dispose() method The following is the complete Get-SPTheme function
function Get-SPTheme([string]$url) { $spWeb = Get-SPWeb -Identity $url $theme = [MicrosoftSharePointUtilitiesThmxTheme]::GetThemeUrlForWeb($spWeb) if (-not([string]::IsNullOrEmpty($theme))) { [MicrosoftSharePointUtilitiesThmxTheme]::Open($spWebSite, $theme) | Format-List -Property @{Name="Theme";Expression={$_Name}}, @{Name="Type";Expression={$_ThemeType}}, @{Name="RelativeUrl";Expression={$_ServerRelativeUrl}}, @{Name="Description";Expression={$_AccessibleDescription}} } else { Write-Host "Default theme is used" } $spWebDispose() }
You can use the function by typing the following:
PS > Get-SPTheme -url http://nimaintranet/subsite
Getting the Available Themes
SharePoint 2010 includes a number of site themes, such as Azure, Berry, and Bittersweet We can retrieve a list of all themes available in a site collection using the GetManagedThemes method of the MicrosoftSharePointUtilitiesThmxTheme class
PS > $spSite = Get-SPSite -Identity http://nimaintranet PS > [MicrosoftSharePointUtilitiesThmxTheme]::GetManagedThemes($spSite) PS > $spSiteDispose()
When we use the GetManagedThemes method, ThmxTheme objects are returned using default formatting for NET classes that have no specific formatting rules associated with them a flat list of all public properties If we want to return only specific properties, we can pipe the results to the Select-Object cmdlet
PowerShell for Microsoft SharePoint 2010 Administrators
The Get-SPThemeName function demonstrated next uses a URL as parameter to access a site collection and then calls the static GetManagedThemes method, piping the results to the Select-Object cmdlet to return the Name property
function Get-SPThemeName([string]$url) { $spSite = Get-SPSite -Identity $url [MicrosoftSharePointUtilitiesThmxTheme]::GetManagedThemes($spSite) | Select-Object -Property Name $spSiteDispose() }
You can use this function by typing the following:
PS > Get-SPThemeName -url http://nimaintranet
Setting a New Theme
ThmxTheme objects support the ApplyTo method, which we can use to set a new
theme for a site When applying a new theme to a site, we first create an instance of the
ThmxTheme class using the static method GetManagedThemes We can use the WhereObject cmdlet to filter on the name of the theme we want to use
PS PS >> >> > $spWeb = Get-SPWeb -Identity http://nimaintranet > $thm = [MicrosoftSharePointUtilitiesThmxTheme]::GetManagedThemes($spWebSite) | Where-Object { $_Name -eq "Berry" }
In this example, we use the Where-Object cmdlet to retrieve the ThmxTheme object where the value of the Name property equals Berry Next, we can use the ApplyTo method on the ThmxTheme object to change the theme of a site in SharePoint 2010 to the Berry theme in this example The ApplyTo method takes two arguments: an SPWeb object and a shareGenerated Boolean value
PS > $thmApplyTo($spWeb, $true) PS > $spWebDispose()
The Set-SPTheme function is used to change the theme of a site in SharePoint 2010 The following is the complete function
function Set-SPTheme([string]$url, [string]$theme) { $spWeb = Get-SPWeb $url $thm = [MicrosoftSharePointUtilitiesThmxTheme]::GetManagedThemes($spWebSite) | Where-Object { $_Name -eq $theme } $thmApplyTo($spWeb, $true) $spWebDispose() }
13:
Managing the Look and Feel of Sites
Here is an example of running the function to change the theme to Azure:
Copyright © OnBarcode.com . All rights reserved.