My reading List

At the top of the v4 masterpage just before the ribbon I found this great Delegate Control called GlobalNavigation.  This control can be used to add content to the top of the page by using a user control.

<sharepoint:delegatecontrol runat="server" controlid="GlobalNavigation" />

If we look at the my profile pages, you can see that it uses this control to add the content on the top of the ribbon menu.

image

 

So if you want to create your own content to add on one of your SharePoint sites You simply have to create a user control and a feature that connects it to the GoblalNavigation Delegate control. You can scope your feature to the farm, web application, site collection or specific site.

1. Create a SharePoint 2010 Project and map a folder to the CONTROLTEMPLATES directory in the 14 hive.

2. Add a new user control to that folder and add your desired content. Below is the HTML markup i added to my user control

<div>
    <h1>
        Hello World
    </h1>
</div>

 

3. Create a feature and a new element.xml. Below is the xml in the element.xml. Inside you see a control element that contains information for SharePoint to implement your control. The Id is the same id as the delegate control. If several controls are targeting the same delegate control the one with the lowest sequence will be used. ControlSrc is the path to your new user control.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Control Id="GlobalNavigation" 
             Sequence="90" 
             ControlSrc="~/_ControlTemplates/DemoNavigation.ascx" />
</Elements>

4. Deploy your solution to see your changes.

 

image

Here is a screenshot of my solution setup.

 

image

Yesterday I wrote about creating a custom theme thmx in SharePoint 2010. But now I would like to add this them to my site definition. I could not figure out how to do it in the onet.xml so I did some digging around in the object model.  Below is an example on how you can get the theme url and the name of the them of a SPWeb.

SPWeb web = new SPSite("http://yourSPSite/").RootWeb;
string themeurl = ThmxTheme.GetThemeUrlForWeb(web); //gets your theme
ThmxTheme theme = ThmxTheme.Open(web.Site, themeurl );
theme.Name; //Gets the name of your theme

 

The ThmxTheme is found in the Microsoft.SharePoint.Utilities namespace. Below is the methods to remove a theme and set a theme. I am not sure what ShareGenerated does yet. But when I know I will post it.

//Will Remove the theme from the SPWeb.
ThmxTheme.RemoveThemeFromWeb(SPWeb web, Boolean RemoveStyles) 
 
//Set a theme on a SPWeb
ThmxTheme.SetThemeUrlForWeb(SPWeb web, string ThemeUrl) 
 
//Set a theme on a SPWeb OverLoaded Function. 
ThmxTheme.SetThemeUrlForWeb(SPWeb web, string ThemeUrl, bool shareGenerated)) 

There is now an easy way in SharePoint 2010 to change some colors and default fonts without having to change a bunch of CSS styles. Just go to site settings and click on “Site Theme”.

image

These themes are stored in a library found at http://YourSharePointPortal/_catalogs/theme/Forms/AllItems.aspx 

If you want to go even further you can look in the files system and you will find thmx files found in the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\Lists\themes Directory.

So the first time I tried to open up one of these files PowerPoint opened up. So I opened up one of the files from Visual Studio 2010 and it looks like the files are in binary format. It would of been nice if they were in xml format but I will have to live with it.

 

So now that I know how the themes work I want to create a Custom Theme that I can use. So it looks like PowerPoint will be my tool to create my custom theme. Below is a step by step guide to create a them in PowerPoint.

1. Open up PowerPoint and go to the Design Tab. Select the Colors button and click on “Create New Theme Colors…”. Change the colors to what you would like and save it.

image  image

2. Now click on the Fonts button in the Themes Section. Change the Font and click save.

image image

3. Expand the themes section and click “Save current Theme…”

image

You should now have your own thmx file. So now in order to use this file in SharePoint 2010 you need to upload it to the theme gallery. Site Settings –> Themes or simply go to http://YourSharePointPortal/_catalogs/theme/Forms/AllItems.aspx and upload your file.

If you would like to include it in your Visual Studio 2010 Project you can install it as a feature element. Below is the Element XML you can use the following

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="ThemesElement" Url="_catalogs/theme" RootWebOnly="TRUE" Path="Themes">
    <File Type="GhostableInLibrary"  Url="CustomTheme.thmx" IgnoreIfAlreadyExists="true" />
  </Module>
</Elements>