Windows Phone 7 Mango goes RTM

OK, so I rarely post stuff likes this, but for this, I will make an exception.

Today, Microsoft officially announced on the Windows Phone 7 Blog that the long awaited update for Windows Phone 7, codenamed ‘Mango’, has reached it’s RTM status. This marks the beginning of the full blown launch world wide for this brand new operating system for mobile devices, next to the startup countries in October and November 2010. This finally means that we can get our hands on devices from Nokia, Samsung and HTC that run in your native language, next to the already supported 5 languages (English, German, French, Spanish and Italian).

I am a Windows Phone 7 user from the start and was immediately impressed by the OS, although I am not completely biassed 😉 But coming from Windows Mobile 6.5, it was a clear change of direction and so far, for the better. It works smoother, faster and better than Windows Mobile ever did and a clear differentiator from Android and iOS.

I hereby congratulate the Windows Phone 7 team in reaching the RTM well in time, so we can enjoy the new features this fall, as well as new devices and better apps. With the Marketplace growing at around 1200 apps a week, Windows Phone 7 matures. Keep up the good work!


FullTextSQLQuery and the Like statement in SharePoint 2010

At my current client, we encountered an issue with some of the custom search web parts. In these web parts, we would perform a custom FullTextSQLQuery against the search index using the Like statement against custom created managed properties. Somehow, the search did not return any results, no matter what the keyword was.

This behavior was kind of strange and indicated that there must be something wrong with the creation of the managed properties, or the population of these properties. Several steps were taken, like again executing a full crawl, remapping the managed properties and so on.

Still, the search did not return any results. This drove me a little bit nuts until I found a post in the social MSDN by Steve Curran. It turns out, Microsoft changed the behavior a little bit since SharePoint 2010. Managed properties on SharePoint 2010 have an additional setting called ‘Reduce storage requirements for text properties by using a hash for comparison’ that influence the way the query behaves when using the Like statement (or the contains statement for that matter). If not checked, any Like comparison against this managed property will always return null, no matter what you put in. Checked this setting, ran a full crawl again and search was working fine.

So thank you Steve!

Personal Edit Mode Panel

Sometimes you encounter stuff in SharePoint that makes you go, ‘huh’? While I was working on the publishing features of SharePoint 2010, a client requested to have custom area on their Intranet where end-users could place their own web parts. Quite easy to achieve by just creating a WebPartZone and have the AllowPersonalization property set to true. So far as so good, but end-users now had to use the Welcome menu (the menu on the top right with your name) to enter the Personal Edit mode. But why not through a button, close to the zone itself that you can also style the way you want?

In short, you only need to call the javascript that is also called if you use the Welcome menu. This javascript is called ChangeLayoutMode(bool personalEdit). If you pass true, the interface is set into personal edit mode, which allows for editing of the WebPart zone with AllowPersonalization set to true. Passing false will set the interface into full edit mode, provided you have permissions of course.

Great, but we also want the button or link to change once in this mode to close this interface and switch to normal view again. Guess what? No such method or button. You close it by navigating away from the page and going back or reload it without QueryString parameters.

Ok, there should be an easier way to do this right? Asking end-users to just navigate away seems odd, so we need to provide a button that does just that, but looks like closing the edit mode. SharePOint comes with the EditModePanel out of the box and although its behavior has been changed slightly since SharePoint 2007, I want something similar for the personal edit mode. That is, just a control that we can include in the master page that shows its contents based on the edit mode active.

Let’s start coding 😉

Setting up the solution

Open Visual Studio 2010 and create a new empty SharePoint project. We will not add any features in this solution. Instead, we just add three classes to the root of the project. I called them PersonalModePanel, PersonalModeDisplay and PersonalModePanelDesigner. The first class will be our control. The second class will contain an enumeration for the different display modes. The last class will be the designer class to enable design time support.


Let’s start with the easiest one, although none of the classes are difficult. The PersonalModeDisplay is an enumeration that defines the display modes that my control supports. In short, there are only two:

  • Display
  • Edit

The first one is the normal state where the UI is not in edit mode, at least not for the personal sections. The second is his counterpart, where the UI is personal edit mode. See the class below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace Boom.ServerControls {

   public enum PersonalModeDisplay
, Edit=2


The PersonalModePanelDesigner class will provide the designer instructions on how the render the control at design time. It inherits from ContainerControlDesigner and just override the FrameCaption and FrameStyle properties. See below:

using System.Security.Permissions;
using Microsoft.SharePoint.Security;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Globalization; 

namespace Boom.ServerControls {

[PermissionSet(SecurityAction.LinkDemand, Name = “FullTrust”), SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
public class PersonalPageModePanelDesigner : ContainerControlDesigner {
   // Fields
   private Style frameStyle;

   // Properties

   public override string FrameCaption {
      [SharePointPermission(SecurityAction.Demand, ObjectModel = true)]
      get {
         return “PersonalModePanelFrame”;

   public override Style FrameStyle
   [SharePointPermission(SecurityAction.Demand, ObjectModel = true)]
   get {
      if (this.frameStyle == null) {
         this.frameStyle = new Style();
         this.frameStyle.Font.Name = “Tahoma”;
         this.frameStyle.Font.Size = new FontUnit(“XSmall”, CultureInfo.CurrentUICulture);
         this.frameStyle.BackColor = Color.LightBlue;
         this.frameStyle.ForeColor = Color.Black;

   return this.frameStyle;


So, now on to the real code. At this point I might disappoint you, as again, nothing fancy going on in here. First the code:

using System.ComponentModel;
using System.Web.UI;
using System.Web;
using Microsoft.SharePoint.Security;
using System.Web.UI.WebControls;
using System.Security.Permissions;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint;
using System.Web.UI.WebControls.WebParts;
using System;

   , ParseChildren(false)
   , ToolboxData(“<{0}:PersonalModePanel runat=server></{0}:PersonalModePanel>”)
   , AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)
   , SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true)
   , AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)
   , SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
   public class PersonalModePanel : Panel, INamingContainer, IParserAccessor {
      // Fields
      private bool shouldRender;

      // Methods
      [SharePointPermission(SecurityAction.Demand, ObjectModel = true)]
      protected override void AddParsedSubObject(object obj) {
         if (this.shouldRender) {

void CalculateShouldRender()
         try {
            HttpRequest request = HttpContext.Current.Request;
            if (request.QueryString.Get(“PageView”) == “Personal”) {
               // At least in edit mode for personal sections.
              if (this.PersonalModeDisplay == PersonalModeDisplay.Edit)
                 this.shouldRender = true;
                 this.shouldRender = false;
            else if (this.PersonalModeDisplay == PersonalModeDisplay.Display) {
               this.shouldRender = true;
            else {
               this.shouldRender = false;

            this.Visible = shouldRender;
        catch (Exception ex) {
           this.Visible = true;

       [SharePointPermission(SecurityAction.Demand, ObjectModel = true)]
    public override void RenderBeginTag(HtmlTextWriter writer) {
       if (!this.SuppressTag) {

    [SharePointPermission(SecurityAction.Demand, ObjectModel = true)]
    public override void RenderEndTag(HtmlTextWriter writer) {
       if (!this.SuppressTag) {

   // Properties
   [Category(“Appearance”), DefaultValue(1)]
   public PersonalModeDisplay PersonalModeDisplay {
      get {
         object obj2 = this.ViewState[“PersonalModeDisplay”];
         if (obj2 != null) {
            return (PersonalModeDisplay)obj2;
         return PersonalModeDisplay.Edit;
      set {
         this.ViewState[“PersonalModeDisplay”] = value;

   [Category(“Appearance”), DefaultValue(false)]
   public bool SuppressTag {
      get {
         object obj2 = this.ViewState[“RenderTag”];
         return ((obj2 != null) && ((bool)obj2));
      set {
        this.ViewState[“RenderTag”] = value;

First, in the class attributes we specify the designer for our control that is of type PersonalModePanelDesigner obviously. We also add some toolbox data, which defines the tag that will be rendered by the intellisense in Visual Studio, in this case <{0}:PersonalModePanel>. The ‘{0}’ just indicates that the designer will insert the TagPrefix here that you will set when registering the control. We will do that later. The rest are security headers that I have just taken from the EditModePanel class.

The class further contains several properties PersonalModeDisplay and SuppresTag that will also be provided to the intellisense and are therefore attributes to our control tag. The real code is located in the CalculateShouldRender method, where we define whether or not the contents of the control should be rendered based on the settings of the control.

CalculateShouldRender method

My first approach was to get the Page object of this page and request the WebPartManager to provide the PersonalizationScope of the page. Turns out that requesting this.Page returns null in the stage of the page lifecycle we are in, so that was a dead end. Instead, I used the querystring method where I just look for the PageView=Personal parameter to be present. If so, the contens should be rendered only if the PersonalModeDisplay is set to Edit. In all other cases, it should not render. Finally, I assign the shouldRender variable to the visible property of the class. And we are done!

Deploy and use the code

Now that we have our control, we can use it in our page designs and layouts. Deploy the assembly to your server using the WSP and open a page layout in SharePoint designer. Register the control in the page by providing the following tag at the top of the page:

<%@ Register Tagprefix=”Boom” Namespace=” Boom.ServerControls” Assembly=”Boom.ServerControls, Version=, Culture=neutral, PublicKeyToken=2847780e0448016d6″ %>

When done, we can insert our control in the page, for example like this:

<Boom:PersonalModePanel runat=”server” PersonalDisplayMode=”Display” SuppressTag=”true”>This is only shown in Display mode</Boom:PersonalModePanel>

<Boom:PersonalModePanel runat=”server” PersonalDisplayMode=”Edit” SuppressTag=”true”>This is only shown in Edit mode</Boom:PersonalModePanel>


So now we have a control that can show different contents based on the personal edit mode of an end-user. For example, we can provide some more instructions in such a panel that is only shown when he or she enters their personal edit mode. Or we can provide different controls to style and control the editing experience. It is just handy 😉 Let your imagination do the talking and use this wherever you like.

Get the VS solution here.

Thanks for making it this far 😉 Leave some comments if you have time!

Styling the Welcome menu

Sometimes I wonder why MS makes some things so hard to do. During the styling of our project, we wanted to move the Welcome menu, also known as the user menu or Personal Action menu to another location on the page.

The control is easy to find and is basically a user control located in the ControlTemplates folder in the 14 hyve. However, that control only defines the menu structure of the control, not the appearance. I started to worry a little, as that probably means that the appearance of the control is defined in code.

Posts by Erik Svenson and Shehan Peruma showed how to change the link color. But I hope that is not the only stuff you can change in the control. How would you ever integrate this into a new publication design?

Hence, I decided to call my favourite friend called Reflector again and dive into the code of SharePoint. Turns out the behaviour of the control is determined by two classes in the CSS, called ms-SPLink ms-SpLinkButtonActive ms-welcomeMenu and ms-SPLink ms-SpLinkButtonInActive ms-welcomeMenu, controlling the active and inactive state respectively.

Basically, the most important part to look for in the Corev4.css (in the Themable folder for publishing sites) is the ms-welcomeMenu class and the classes derived from that. Controlling the font color, family, background and other options is quite easily done through these classes:

.ms-welcomeMenu {
   padding:2px 5px 3px;
   margin:0px 3px;
   border:0px solid transparent;
.ms-welcomeMenu a:link {
.ms-welcomeMenu a:hover {
   text-decoration:none !important;
} {
/* [ReplaceColor(themeColor:”Dark2-Lighter”)] */
/* [RecolorImage(themeColor:”Dark2-Lightest”,includeRectangle:{x:0,y:489,width:1,height:11})] */
   background: url(../img/backgrounds/bg-sprite-tabbar.png) 100% 0 no-repeat;
/* [ReplaceColor(themeColor:”Dark2″,themeShade:”0.8″)] */
} a:link {
/* [ReplaceColor(themeColor:”Light1″,themeTint:”0.9″)] */

What I did in above CSS override is changing .ms-welcome a:link and .ms-welcome a:hover to change the font color of the inactive state.
To change to color of the font as soon as the mouse is over it, add the style a:link.

Secondly, I have overridden the background in to show a custom made image. If IU left it, it would show the dark background of the top bar, which is something I do not want on a white background ;-).

By default, the ms-welcomeMenu has a transparent background in the inactive state, as it should be and therefore blends in into its container. Remember though that you should override these classes in a separate CSS file and be sure it is loaded last (or at least after Corev4.css) in the master page. Also, you cannot remove any styles, just override the settings already made.

Finally, you can do the same for the SiteActions menu. You can do that by looking for the classes called .ms-siteactionsmenu.

Branding SharePoint Sites, how to get started

Many of us out there have encountered it before; How do I make SharePoint look the way I want it to, without destroying any of the functionality that comes out of the box? In my current project, we face the same challenges that leave us sometimes puzzled on why Microsoft has chosen certain design approaches.

One of those things is the use of table style design, especially in the WebPartZone and WebPartChrome controls. It really frustrates designing based on DIV’s, which is the standard nowadays.

The second thing is the complete overload on CSS that SharePoint applies to pages to handle the styling of the various elements. In one way, this allows for very detailed control over UI elements, but in the other hand makes it almost impossible to apply a generic style across all pages and controls.

Fortunately, I was not the only one facing this issue. So here are some of the links I found very useful when starting to design Intranet en Internet web sites based on SharePoint 2010.

To start off, Andrew Connell and Randy Drisgill provided a quite extensive article on how to approach Branding with SharePoint 2010. This article is excellent and will provide you a flying start in any design and helps to understand the various elements contained in a SharePoint master page and the styles that are applied to them.

When web designers start developing their front-end design their first course of action is to reset all the css styles that are applied by default. Doing that on SharePoint will, well, confuse SharePoint to say it mildly. Kyle Schaeffer has developed a reset css specific for SharePoint 2010 that gives front-end designers a head start in applying their custom css on SharePoint.

CSS is basically the keyword in styling SharePoint. Not by introducing your own classes, but understanding the 200+ classes Microsoft introduced themselves and which does what. One of the absolute guru’s on this front is Heather Solomon that also provided a complete reference to all the styles that are applied to certain UI elements and what they said. A must read for any developer that needs to style SharePoint. Unfortunately, only for SharePoint 2007 now, but I am sure she will also provide one for SharePoint 2010.

Master pages and Page Layout form the basics on any SharePoint site and customizing can be challenging. Andrew and Randy provide a good starter.master that has all the essential elements in place and also contains good comments on which section does what. Couple of things I encountered that are crucial:

  • Do not remove the s4-workspace, s4-bodyContainer and MSO_ContentDIV divs.
    Doing so will really mess up your user experience with SharePoint, especially when entering the edit modes.
  • When going for a fixed width site, which is quite common these days, apply the s4-nosetwidth class to your workspace div. This will instruct the javascript behind the scenes not to touch the widths set in the CSS definitions.
  • Use the s4-notdlg class for any element you do not want to show in the modal dialogs of SharePoint. Failing to do so will show your beautiful header in full power within small dialog boxes.
  • Accept that SharePoint controls output their HTML in a certain way. Yes, some use tables to structure it, deal with it. If have played around with ControlAdapters and basically found that they do more damage than they solve. For one thing, because a lot of the html rendering methods of controls are a) internal and b) sealed, there is no way of reaching it, only to completely override it. Thing is, they introduce the object DOM in the HTML that you will then omit…and shake up SharePoint.

In short, styling SharePoint can be a tedious task. With these links, I hope you guys get in the right direction quick. I wished I knew them before finding out the hard way 😉


Using Social Tagging to create a Favorites web part

On my journey in the new features of SharePoint 2010, my attention was caught by the so-called ‘Social’ features of SharePoint 2010. In particular, the use of the tagging and rating functionality had my interest.

A client wanted to give end-users a quick way to register favourites on their Intranet. I immediately thought of the ‘I Like It’ button in the Ribbon, where end-users can quickly tag a page that they like. In their profile, they could see all the tags and the url’s where they placed the tags.

Unfortunately, I could not find a web part that could display the tags for a given user for a specific url, or vice versa. The latter is what I needed. And so I decided to write some small code to do that for me.

In fact, the basic principles are simple. We connect to the Users profile, retrieve their tags, get the tag we want to filter on, retrieve the urls for that tag and display those in a list. Easy right?

Social Tagging

SharePoint 2010 stores tags entered by users in their user profile. You can view the tags you entered by going to your profile page and review the Tags and Notes section. That sections shows all the notes and tags, as well as a history (activities) trail for that particular tag or note. Simply put, the information is there.

I tried to find the controls SharePoint is actually using to generate these views, but was not able to make those available through a web part. Secondly, I want to be able to control the output and settings, so I will go with my own web part anyway.

Setting up the solution

I would like to keep this post simple, so I will not go into the specific details of formatting and making things configurable. I will just show the principle.

So, start Visual Studio 2010 and create a new Empty SharePoint project. Add a new item of the type Web Part. Give it all some reasonable names and your solution explorer should resemble the following picture:

Open the Favourites.cs file and we will start adding the code. Add the following references to your project:

  • Microsoft.Office.Server (needed for the UserProfile servercontext)
  • Microsoft.Office.Server.UserProfiles (needed for the UserProfiles)
  • Microsoft.SharePoint.Taxonomy (needed for the term store)
  • Microsoft.SharePoint (needed for the normal SharePoint objects)

 GetUserUrlsByTag method

Below code shows the GetUserUrlsByTag method that will retrieve all urls from the current user for a specific tag.

private Uri[] GetUserUrlsByTag(string tag)
   // first get the service context
   SPContext ctx = SPContext.Current;
   SPServiceContext serviceContext = SPServiceContext.GetContext(ctx.Site);

   // Then load the UserProfileManager

   UserProfileManager mngr = new

   // Get the user’s profile

   UserProfile currentProfile = mngr.GetUserProfile(false);

   // If the user has a profile, get the SocialTagManager
   if (currentProfile != null)
      SocialTagManager smngr = new

      // Get the terms for the user

      SocialTerm[] terms = smngr.GetTerms(currentProfile);
      SocialTerm favTerm = null;

      //Iterate through the terms and search for the passed tag
      foreach (SocialTerm t in terms)
         if (t.Term.Name.ToLower() == tag.ToLower())
            favTerm = t;

      // If found, get the Urls and return
      if (favTerm != null)
         return smngr.GetUrls(favTerm.Term, currentProfile);
         return null;
   return null;

The method needs to return an array of urls that have a certain tag applied to it. We first set up the context and service context for this site. We then create a UserProfileManager based on the service context and retrieve the UserProfile of the current user.

If the current user has a user profile, we create a SocialTagManager that will perform the bulk of the functionalities we need. We then get all the SocialTerms for this user. It would be better if we could request a specific Term to be retrieved, but unfortunately I have not found a method to do so. So instead, we will need to iterate through the returned terms until we find the one we want to filter on. I would be much obliged if someone know a better method of doing this. For now, it works.

Once we found the term we are interested in, we can request all the url’s for that tag by calling the SocialTagManager.GetUrls method, passing the term and the profile.

And we are done! The web part I coded contains the method call and will output all the url’s in a list. However, you can style it in the any way you want obviously. Now when users click the ‘I like it’ button in the ribbon, it will show up in their favorites web part.

To be complete, the code in the CreateChildControls method of the web part.

protected override void CreateChildControls()
      Uri[] urls = GetUserUrlsByTag(“I Like It”);
      HtmlGenericControl table = new

      if (urls != null)
         foreach (Uri url in urls)
            HtmlGenericControl row = new
            HtmlGenericControl cell = new

            HyperLink link = new HyperLink();
            link.NavigateUrl = url.AbsoluteUri;
            link.Text = url.AbsoluteUri;
         Label lbl = new Label();
         lbl.Text = “No favourites found.”;
   catch (SPException ex)
      Label lbl = new Label();
      lbl.Text = ex.ToString();

And finally the output:

Improvements on this code

So, a couple of things can obviously be improved in this little piece of code.

  1. Make the input and output configurable. So selecting the term to filter on and exporting the output through XML, which allows us to use XSL for the rendering.
  2. Get details about the url’s in the profile. For example, we could retrieve the page title rather than the url by obtaining that from the page instance in the pages library.
  3. Add a button or control to the ribbon or expose that as a separate web part that does the favourite tagging. That way we can control the term we call favourite (for example, MyFavourite instead of I like it)
  4. Improve the filtering on the terms. As soon as a user gets a lot of terms, the filtering might slow down.


The new Social framework of SharePoint 2010 can be used for very neat things. To bad some of the features are not exposed more through web parts, but I am sure the community will provide their own sets of controls that expose the power behind Social tagging and rating. You can find the VS project for this example here.

Till next time!

SharePoint's Booming world

%d bloggers like this: