maandag 18 april 2011

SharePoint 2010 refinement panel

When you do a search in SharePoint 2010 and land on the results page, by default on the left you will see the refinement panel. This panel will show up if there are enough results being returned by the system. I think default the minimum is five.

At some point you might want to add your own custom categories. This is already explained in a lot of other posts but I want to make some things clear. Things that are sometimes incorrectly postulated in some articles.


If you want to add your own category, edit the options of the refinements panel and open the 'Refinement' category. You will want to edit the 'Filter Category Definition' xml. (tip: for easy editing, copy paste the XML here to reformat: http://www.shell-tools.net/index.php?op=xml_format).

You will notice that each category is represented by a 'Category' tag with all kinds of options. Basicaly, you just need to copy paste such a tag and edit its options. Don't forget to turn off the 'Use Default Configuration' option or none of your changes will be saved.


1. Create a managed property for your custom category. Anything of which you can make a managed property, can be used as a category (as far as I know).

2. The 'Type' property can end with 'ManagedPropertyFilterGenerator' for any column that is not a managed metadata column or 'TaxonomyFilterGenerator' if the column is a managed metadata column.

3. Your managed metadata does not have to be in lower case for it to show up. Just use the casing you used.

4. Very important property to notice is the 'MetadataThreshold' option. This option defines how many times the column must appear in the search results before the category becomes visible in the refinement panel.

5. Tip: you can only create a managed property from a column that is actually being used. So there must be at least one item which has the metadata column and it must have data. You must then crawl the complete system for it to become available when configuring managed properties.

6. Tip: First make sure you can search your managed property by typing this in the search box: 'managedPropertyName: valueToSearch'.

7. Tip: if your managed metadata does not exist (not configured or typo in the XML), the refinement panel will tell you. So if you configured it correctly and no error message is shown, check if the other options are ok.

vrijdag 15 april 2011

Doing a redirect in ItemUpdated event

Sometimes it might be handy to, based on an update of an item, redirect the user to a different page. For example, if a given metadata field of the item has a certain value, redirect the user to another page.

Although this request seems fairly simple, it's not so easy to do. Why?

1. If you want to do it during ItemUpdating, your event thread will not be finished and your item will not actually be updated.
2. If you do it during ItemUpdated, you will not have access to the HttpContext so you cannot use SPUtility.Redirect. Or can you ... ? :) I really lost a day or more searching for this but now have a working solution.

It seems that with some workarounds, you can have access to the HttpContext in the ItemUpdated. I will here briefly explain how to do it:

1. Create two private global variables in your event receiver:
private HttpContext _httpContext;
private static HttpContext _sHttpContext;

2. Get a hold of the HttpContext in the constructor
_httpContext = HttpContext.Current;

3. In ItemUpdating, again get a hold of the HttpContext
_sHttpContext = _httpContext

4. Use SPUtility.Redirect and _sHttpContext to redirect to a page of your choice.

Unable to create a new group in the SharePoint 2010 managed metadata service

I was having this problem lately and read some articles that explained me to go to the list of service applications via the central administration, select managed metadata service from the list, click the 'Administrators' button in the ribbon and add myself to the list giving me 'Full control' access. This didn't change anything and it's also not necessary if you are a farm administrator.

What is important is that you just add your self to the list of managed metadata owners in the first screen of the managed metadata service management tool which you can access via any site collection via the site settings. This allowed me to create new groups, term sets and terms.

Managed metadata service connection not available

After a fresh installation of your SharePoint 2010 environment, you could face this message. This is because the managed metadata service has not yet been configured correctly. The easiest way to do it in my opinion is by using the configuration wizard in the central administration.

Open central administration and click on 'Configuration Wizard' in the left bar. When you start the wizard, you will get a list of all possible services. In the list, select managed metadata service. You can of course also enable/disable other services. Go to the next step to start the configuring process. The last step also lets you create a new site collection but it's optional.

maandag 11 april 2011

Passing data to a visual web part user control

In Visual Studio 2010 it's now possible to create a web part based on a ascx user control. This was of course also possible in SharePoint 2007 but you can now do it more quickly via the provided Visual Studio templates. In the web part code itself, the class inheriting from the webpart class, you can load the user control in two different ways:

1.
Control control = Page.LoadControl("pathToAscx"); Controls.Add(control) ;
2.
Control control = Page.LoadControl(typeof(nameOfYourAscxClass), object[]);
Controls.Add(control);

The first one just creates an instance of your user control passing no parameters to the constructor. Via the second one you can also pass parameters to the constructor. Number, order and type of these parameters must be the same as the those of the constructors. Now sometimes you want to add properties to your web part to let the user configure some options.

You could use the second LoadControl to pass these parameters to your user control but you can also take this approach:

1. Create properties in your UserControl class
2. Assign them before adding the control like this:
MyControl myControl = (MyControl)Page.LoadControl("pathToAscx");
myControl.property1 = "value1";
myControl.property2 = "value2";
Controls.Add(myControl);