Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a PowerShell script creating new site collections, each containing a root SPWeb, on my SharePoint web application.

I have a THMX file that I'm trying to apply to each SPWeb that the script creates, but I'm not sure how best to do this.

  • I can use ThmxTheme.Open(site, URL) to get a handle to the theme once it is uploaded.
  • I can use ThmxTheme.ApplyTo(web) to apply the theme to the SPWeb once I have the handle to it.
  • However, I can't figure out how to upload the theme in the script.

In the past, I've scripted the uploading of images to a site's Asset Library, for example, but I can't find the equivalent of SPWeb.Lists.EnsureSiteAssetsLibrary() to get a handle to the Theme Gallery.

Can anyone tell me

  1. how to get the THMX file into the theme gallery, and
  2. if there's an easier way to script setting the theme to an SPWeb than that bulleted above (e.g. if there's a way to get a handle to the theme without needing a server-relative URL)?
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

I think the theme gallery is one of the default libaries created from SPRequest/COM (I can't see it in the hive) So you could use the same trick that site provisioning uses, wait looping until certain lists are available.

#create site collection
$filename = "c:\blah.thmx"
$bytes = [System.IO.File]::ReadAllBytes($filename);
$name = [System.IO.Path]::GetFileName($filename);
$list = $null
while($list -eq $null) {
    Start-Sleep 5 #wait for list to be created
    $list = (get-spweb "http://siteurl").Lists |? {$_.Title -eq "Theme Gallery"}
}
#upload theme
$list.RootFolder.Files.Add($name, $bytes);

And it looks like ApplyTo is the way to go as ThemingProcessor is internal

Though there seems to be a sequence issue to be careful of, but you should be okay in script

http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/dcda5e8b-4569-4d26-ab17-32eaa95d33b8

share|improve this answer
    
This work great, thanks. One more thing: I'd like $filename to be relative if possible (".\blah.thmx"), but doing this in my script looks for "C:\windows\system32\blah.thmx" rather than "C:\path\to\script\blah.thmx" in ReadAllBytes. Is there a way to fix this? –  Rawling Apr 19 '11 at 8:11
    
Got it, Resolve-Path does the trick. Cheers again :) –  Rawling Apr 19 '11 at 8:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.