SharePoint 2010 Dialog Window Branding

On August 24, 2011, in Branding, CSS, Dialog Windows, by matdesmarais

It has been a while since my last article. We have been extremely busy here with summer vacation and projects coming to term. Now that September is just around the corner, it is time to get back in gear. So here is another SharePoint 2010 branding tip: Branding Dialog Windows!

When you start applying your own custom style to a SharePoint site one thing you will start noticing is that the dialog windows also take on the styling that is applied to the main page. To prevent some items from appearing in the dialog windows, we need to add the following class to the html elements we want to hide:


Once placed in the class of an element it won’t be displayed (you can do this with items like the header div, the top navigation div, etc.)

But what happens if you apply a css class to an element in the homepage that cannot be hidden in the dialog box, such as the main content div or the bodyContainer div?

In that case you can use the following trick:

.s4-bodyContainer { width:950px; border: 1px black solid; } .s4-bodyContainer { width:400px; border: none; }

The “” placed before an existing style class such as s4-bodyContainer will let you override the display when the page is in a dialog window. The main tag in the render takes on the class of ms-dialog and css will cause inheritance to this overridden css class.

There is more to come soon so stay tuned!


Updated: Provisioning Managed Metadata Columns

On August 11, 2011, in C#, SharePoint, Taxonomy, by matdesmarais
SharePoint 2010 now includes functionality for Managed Metadata. These new features add a lot of new features for end users but also add a level of extra complexity for us as developers. These issues are already discussed at length here: so I won’t get into the details of the issues but only provide a quick guide for provisioning these columns.


Here are the steps to take to provision Managed Metadata columns.
  • Start with an empty SharePoint Project in Visual Studio 2010.
  • Add a new Item to the project and select the Empty Element template.
  • In this new Element file, add the following xml definition for a Managed Metadata column and it’s associated hidden Note field:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
 <Field ID="{F2B1920F-2025-41EB-84DC-F59E29D17D33}" Type="TaxonomyFieldType" DisplayName="Contributor" ShowField="Term1033" EnforceUniqueValues="FALSE" Group="Custom Metadata" StaticName="Contributor" Name="Contributor" Overwrite="TRUE">
         <Value xmlns:q6="" p4:type="q6:string" xmlns:p4="">{35732AE5-9782-42F6-A44B-AF07ED2809CE}</Value>
 <Field ID="{35732AE5-9782-42F6-A44B-AF07ED2809CE}" Type="Note" DisplayName="Contributor_0" StaticName="ContributorTaxHTField0" Name="ContributorTaxHTField0" ShowInViewForms="FALSE" Required="FALSE" Hidden="TRUE" CanToggleHidden="TRUE" RowOrdinal="0" />

Updated: Aug 11, 2011 updated to add the Customization ArrayOfProperty that is required to make your content type be re-deployable. Without this, you will get a message that the hidden note field already exists.

  • Then we will add a new Content type to consume this new column. To do this add a new Item to the project and select Content Type in the templates. Provide a name and pick the content type that will be the base for this new content type.
  • In the Elements.xml file of the new content type add the following FieldRefs:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
  <!-- Parent ContentType: Article Page (0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D) -->
  <ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D00426fe9e90dd14ec8a88a4599ec58c3fd"
               Name="Article Page"
               Group="Article Page Layout Content Types"
               Description="Base for all article pages"
     <FieldRef ID="{35732AE5-9782-42F6-A44B-AF07ED2809CE}" Name="ContributorTaxHTField0"/>
     <FieldRef ID="{F2B1920F-2025-41EB-84DC-F59E29D17D33}" Name="Contributor"/>
  • Make sure the Hidden field is added first so there won’t be an automatic Note field created by the Managed Metadata column and cause conflicts.
  • Now we need to add a feature event receiver on Feature1 of the project. (right clicking the Feature1 will give you the option of creating this)
  • In the feature event receiver, we need to uncomment the FeatureActivated block and add the following code to it:
using Microsoft.SharePoint.Taxonomy;

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    SPWeb web = properties.Feature.Parent as SPWeb;
    SPSite sitecoll = web.Site;

    //Attach Metadata Fields to Store
    AttachManagedMetadataFieldToStore("{F2B1920F-2025-41EB-84DC-F59E29D17D33}", "TaxonomyTermSetName", "TaxonomyTermGroupName", web, sitecoll, "{35732AE5-9782-42F6-A44B-AF07ED2809CE}");
  • You will also need the following helper functions to complete the feature:
public Group GetByName(GroupCollection groupCollection, string name)
	if (String.IsNullOrEmpty(name)) throw new ArgumentException("Not a valid group name", "name");
	foreach (var group in groupCollection)
		if (group.Name == name)
			return group;
	throw new ArgumentOutOfRangeException("name", name, "Could not find the group");

public void AttachManagedMetadataFieldToStore(string guid, string TS, string TG, SPWeb web, SPSite site, string NoteGuid)
	Guid fieldId = new Guid(guid);
	if (web.Fields.Contains(fieldId))
		TaxonomySession s = new TaxonomySession(site);

		if (s.DefaultKeywordsTermStore != null)
			var termStore = s.DefaultKeywordsTermStore;
			var groupCol = termStore.Groups;
			var group = GetByName(groupCol, TG);
			var termSet = group.TermSets[TS];

			TaxonomyField fld = site.RootWeb.Fields[fieldId] as TaxonomyField;

			// Attach Properties to field
			fld.SspId = termSet.TermStore.Id;
			fld.TermSetId = termSet.Id;
			fld.AnchorId = Guid.Empty;
			fld.TargetTemplate = string.Empty;
			fld.TextField = new Guid(NoteGuid);

This SharePoint solution can be packaged up and will provision the columns for you on activation.

Please note: Managed Metadata Columns do have limitations like not having any support in Infopath, not being supported in datasheet views, not being supported by Office 2007, etc… The complete list can be found on this post here: 

I will add a second part to this article soon on how to create the taxonomy term store using an xml import file instead of the OOTB csv import file so the GUIDs remain unchanged from deployment to deployment (handy for dev/qa/uat/prod multi-level environments.)