What's New
0

SharePoint 2010: Automatically Reset to the Default Theme in Code

When you want to reset your current theme that has been applied to your SharePoint site in code, you may try code like:

web.ApplyTheme("default");

but that won’t work because there is no "default" theme.

After looking in the SPTHEMES.XML file found in the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033 folder, you do see there is a theme with a theme name of "none". That makes sense so you try:

web.ApplyTheme("none");

But often that still won’t work. Frustrating. Keep searching and after a review of Microsoft’s documentation on the SPWeb.ApplyTheme method, you see it.

Caution
Use this method only when the UI is in backward compatibility mode (SPWeb.UIVersion = 3).

Not too many of us use UIVersion = 3 in SharePoint 2010, so what do you do now?

Easy. Use the replacement class, ThmxTheme (found in Microsoft.SharePoint.Utilities), in particular the ThmxTheme.RemoveThemeFromWeb method.

Example:

ThmxTheme.RemoveThemeFromWeb(site, true);

Where site is the SPWeb and the bool value states if you wish to also remove the theme’s styles. Setting this to true will remove the theme specific styles that was created when the theme was applied to the web, but I have found that setting this to true can cause issues because of security concerns. I suggest you try settings the bool value to true if you wish to have this method remove theme styles files, but if you receive errors, set this to false and it will likely work. This is not the best for housekeeping, but may make your life easier.

As a quick example, say in a feature receiver when you deactivate a feature, the following code would remove the theme from an entire site collection if the feature is scoped to the site level.

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
	//go and get the root site collection
	SPSite siteCollection = properties.Feature.Parent as SPSite;
	if (siteCollection != null)
	{
		SPWeb topLevelSite = siteCollection.RootWeb;
		foreach (SPWeb site in siteCollection.AllWebs)
		{
			//reset the theme in case one was applied
			ThmxTheme.RemoveThemeFromWeb(site, true);
		}
	}
}
0

SharePoint Saturday Silicon Valley – June 2nd

For those of you in the Northern California region, mark your calendars. SharePoint Saturday Silicon Valley (#SPSSV) is this June 2nd in San Jose. I am proud to say that I will be presenting a session on SharePoint Branding, titled SharePoint Branding – Change Your Look. This will be geared towards an introduction to SharePoint Branding, but bring your questions and attend my session. I will be happy to answer as many questions as possible. I will be around all day so if you miss my session, no worries, find me.

Information regarding this event direct from the SPSSV website:

SharePoint Saturday Silicon Valley is an educational, informative & lively day filled with sessions from respected SharePoint professionals & MVPs, covering a wide variety of topics focused on Microsoft SharePoint technologies.

SharePoint Saturday Silicon Valley is FREE, open to the public and is your local chance to immerse yourself in SharePoint!

Location:
Oshman Jewish Community Center
3921 Fabian Way
Palo Alto, CA 94303
www.paloaltojcc.org

Map and directions from Google Maps

www.sharepointsaturday.org/siliconvalley

0

SharePoint 2010 – Adding a Fixed Footer to your SharePoint Minimal Master Page

In a previous post I explained how to add a fixed footer to SharePoint 2010 sites. The idea of the fixed footer is that it would be placed on the bottom of the window, fixed to the browser’s bottom. The catch with SharePoint 2010 is that SharePoint removes the browser’s scroll bars and replaces them with scrollbars attached to the #s4-workspace div container. Our solution was to use a little javascript code to resize the s4-workspace container to provide room for the fixed footer. To see this complete solution, please refer to my previous post.

A question was raised by a fellow reader, Ridik. The question was how could this fixed footer be applied to a minimal master page when used for My Sites and Search Results. The catch with the minimal.master master page is that there is no #s4-workspace div.

Luckily the solution ends up being easier to implement then a fixed footer on standard SharePoint sites. The one catch is that the scroll bars will appear slightly different because we can now safely use the browser scroll bars.

Create the Fixed Footer

Again, creating a fixed footer is easy enough. We will use the same solution as the previous post. All you need to do is create a new div and add it most anywhere in your Master Page. It can go almost anywhere because it will be fixed to your browser window. I recommend right after the closing </div> tag of your #maincontent div as found in the default minimal master page. So after you create a copy of your minimal.master Master Page, because we all know you should never modify the minimal.master file directly, add the following code, right after the closing tag of the #maincontent div.

<div id="footer-fixed">
</div>

You can of course add whatever content, child tags and containers, etc, you want within this footer-fixed div. Next we need to provide basic css for this div, that has an id of footer-fixed. Add the following css to a location of your choice.

If you choose to add the css to the head section of your Master Page, add the following just before the closing </head> tag.

<style type=”text/css”>
#footer-fixed {
	position: fixed;
	height: 60px;
	width: 100%;
	bottom: 0px;
	left: 0px;
	background-color: #000;
}
</style>

Or just add what is between the <style></style> tags in an alternative CSS location or your own custom stylesheet.

What this little block of CSS code does is tells the html element with an id of footer-fixed, our footer div, that it’s position is fixed to the browser window, that its height is 60 pixels (you can change this as needed), it’s width is 100%, or the entire width of the window, and to then position the element 0 pixels from the bottom of the browser window and 0 pixels from the left of the browser window. I have set the background color to black just so that the footer is more visible without any content.

You can change the height to fit your needs, but I do not suggest adding margins or padding to this footer div. If you need padding and margins then I suggest you add a child div within this footer-fixed div and apply the margins and padding here. Originally this was more important for our previous solution and it is less important here. But to stay consistent, I suggest the primary footer container have no padding or margin.

One last piece of css to add. When this footer gets placed on the page it is placed over any other containers under it. It is taken out of the flow of the rest of the site. What ends up happening is that the bottom portion of your maincontent div might get hidden because it does not know the footer is there, so you need to add padding at the bottom of your maincontent div equal to at least to the height of your footer, i.e.

<style type=”text/css”>
#maincontent {
	padding-bottom: 60px;
}
</style>

If you added the style directly to your Master Page, go ahead and save the Master Page if you wish and set it as your custom master page for now. It should be your custom master page because My Sites Hosts pages as well as search results pages use the custom master page. If you added the css to a custom stylesheet, update your Master Page to reference this stylesheet and save. Reload your site and you will see the fixed footer.

Unlike for standard SharePoint 2010 pages, no additional javascript is required. That’s it.

Conclusion

The primary complaint with this solution is that the scroll bars are now outside of the right of the footer, where-as in our other post the right scrollbar was above the footer. To make this post simple I provided a quick way to add a fixed footer. If you want to be consistent with your scroll bars then you would need a more complex solution. The premise of this would be to surround your s4-mini-header and maincontent divs with a container div similar to the s4-workspace div. The styles of this container div would including a fixed width, fixed height as well as overflow set to autoThen once the page loads using javascript, or I would suggest jquery to size this container div to fit within the browser, but provide space for the footer. Don’t forget to turn off the scroll bars in the body.

I will try to build up this solution in a third post but the above solution will hopefully help you get started.

0

PixelMill Will be at SPTechCon Boston 2012


SharePoint Conference 2011
I am proud to say that PixelMill will be an Exhibitor at BZ Media’s upcoming SPTechCon (#SPTechCon) in Boston, being held at the Westin Copley Place Hotel this July 22nd through the 25th (Sunday through Wednesday). You can learn more about the conference from the SPTechCon website, but don’t forget to use the code “pixelmill” during your registration process to save an additional $200.

I was at SPTechCon San Francisco in February and it was quite an amazing mix of developers, business executives, speakers and sponsors. If you are looking for a good conference on SharePoint I have to say that SPTechCon puts on one of the best. They offer a great assortment of technical classes presented by very talented speakers including many MVP’s.

The list of technical classes was just released. Check it out and pick your classes now.

Some classes that I would recommend you not miss (some have time conflicts, sorry, but they are good, so plan ahead).

  • Best Practices for SharePoint User Adoption by Susan Hanley
  • Enhancing SharePoint with the Power of jQuery by Phill Duffy
  • Intro to Branding SharePoint 2010 in the Farm and Online by Randy Drisgill and John Ross
  • The Ribbon UI and Custom Actions in SharePoint 2010 by Geoff Varosky
  • Getting the Best use out of SharePoint Designer 2010 by Asif Rehmani
  • Make SharePoint Look Good! By Heather Solomon
  • Creating Dynamic Taxonomy-Driven Navigation For Publishing Sites by Andrew Connell
  • SharePoint In The Cloud by Richard Harbridge
  • Popping the Hood: How to Create Custom SharePoint Branding by Randy Drisgill and John Ross
  • Learn How to Put HTML5 in Your SharePoint Master Page by Dustin Miller and Heather Solomon

For those attending, be sure to drop by the PixelMill booth and say hello. Tell me about your SharePoint Branding success stories, or come on by and we can commiserate about how SharePoint makes our lives interesting.

1

SharePoint 2010: Allow Server Side Code – Inline Code Blocks

One of the great features of SharePoint is that it is built on-top of .Net, thus allowing nearly unlimited modifications via additional code. Most of the time this additional functionality would be added via Web Parts, features, etc, but sometimes it would be nice to add inline code to a specific SharePoint managed aspx page. But by default SharePoint does not allow code blocks in .aspx pages.

The way around this is well documented but I keep getting asked can you add code blocks directly in your page, and if so, how. It’s quick and easy so let me explain.

First, an example

Say you want to create your own Search Results page. There are many ways to do this and I will leave a full explanation to another article. For this example I simply made a copy of the SearchResults.aspx file found in the Layouts directory in the 14 hive, added it to the root directory of my SharePoint site in SharePoint Designer and renamed it OSSSearchResults.aspx. Anyhow, say in your Search Results page you want to have the search string displayed somewhere on your page. You might add a line of code like:

<h1><SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,searchresults_pagetitle%>" EncodeMethod='HtmlEncode'/> : <% SPHttpUtility.HtmlEncode((Request.QueryString["k"].Length > 20) ? (Request.QueryString["k"].Substring(0, 20) + "...") : Request.QueryString["k"], Response.Output); %></h1>

Easy enough. This code will take the Querystring, and if it’s over 20 characters long, truncate it, and display it one the page. Yes, you normally would not blindly trust the user’s input and display it on the page, even with SharePoint security, but for this example, it works. If you add this code block, then load your page in a browser, you receive an error, “An error occurred during the processing of /OSSSearchResults.aspx. Code blocks are not allowed in this file.”

SharePoint-Branding-Code-Blocks-Error

To enable code blocks in this file, on the server you need to open this site’s web.config file, by default found in c:\inetpub\wwwroot\wss\VirtualDirectories\”the site directory”, and look for the following code block in the <Configuration> -> <SharePoint> section.

<SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">
   <PageParserPaths>
   </PageParserPaths>
</SafeMode>

By default the <PageParserPaths> section is blank. All you need to so is add the following to the <PageParserPaths> section:

<PageParserPath VirtualPath="/osssearchresults.aspx" CompilationMode="Always" AllowServerSideScript="true" />

i.e.

<SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">
   <PageParserPaths>
      <PageParserPath VirtualPath="/osssearchresults.aspx" CompilationMode="Always" AllowServerSideScript="true" />
   </PageParserPaths>
</SafeMode>

Notes:

You can use wildcards for the VirtualPath value, i.e. VirtualPage=”/Pages/*” to allow all pages to include code blocks. I wouldn’t suggest this though, add a <PageParserPath> section for each page you wish to add code blocks to.

There are three values for CompliationMode:

Always [default value] Always compile this page.
Auto SharePoint will not compile the page if possible.
Never This page should never be compiled.

AllowServerSideScript can be set to true or false. In this case it must be true.

For wildcard paths, you can add another tag, IncludeSubFolders=”true” to <PageParserPath>.

That’s it, save the web.config file and your page should now load.