by Andreas

How to debug custom Sharepoint webparts

If you create a test suite for unit testing your custom Sharepoint webpart you might come across the following warning when running your tests:

The following module was built either with optimizations enabled or without debug information


You’ll also find that you’re unable to step into the methods while debugging, as if you don’t have access to the source of the assembly.


imageThe reason for this is that Sharepoint modules are signed with a Strong Name Key, because they are supposed to be deployed to the GAC. The solution is therefore to ensure that you deploy your web part before running your unit tests, and you’ll find that the warning message disappears and you’ll be able to debug the web part source as well.

by Andreas

Sharepoint debugging – process terminated by IIS

”The web server process that was being debugged has been terminated by IIS”

When debugging Sharepoint components you’re likely to come across this error message. It is easily fixed by turning off the ping IIS is sending the worker process at regular intervals to keep it alive.

Go to IIS Manager, select the Application Pool used by your Sharepoint app, choose advanced settings and turn the “Ping Enabled” setting under “Process Model” to FALSE:


by Andreas

Sharepoint memory leak – or not?

Potentially excessive number of SPRequest objects (448) currently unreleased on thread 28.  Ensure that this object or its parent (such as an SPWeb or SPSite) is being properly disposed

There is no reason to freak out because your Sharepoint logs are filled with warnings like that one. What it is saying is that your environment has got a fair bit of SPWeb/SPSite objects currently undisposed, but this is not necessarily a memory leak. If you enumerate through a high number of SPWeb objects (like the MySite of every user) the number of objects will exceed the configured threshold, and these messages will appear.

So how do you determine that there is a memory leak? First, search for the following error message:

8l1n An SPRequest object was not disposed before the end of this thread

(or just 8l1n since that’s the unique ID for this message)

THAT’s a bad sign. That message means that at the end of a running thread there was no call to an object’s Dispose() method, and it will float around until eventually getting picked up by the garbage collector. This is a memory leak.

To solve the problem, have a read at this page to see the “best practices” for disposing objects. It is based on Windows SharePoint Services 3, but should still be used as a reference for SP2010.

by Andreas

Sharepoint is eating up my hard drive!

If your available free hard drive space is steadily decreasing, despite efforts to clean up your mail box, temporary internet files, browser download folder and Windows Update folder – check your local Sharepoint installation (use something like WinDirStat to get a full overview of where your space has gone, or check directly in the folder where your SQL database files are stored (e.g. C:Program FilesMicrosoft Office Servers14.0DataMSSQL10.SHAREPOINTMSSQLDATA)).


Over time, the log databases will get really big unless you reconfigure this yourself. I recently deleted the .log file for my content database, but now only a week later the 4GB I released were reduced to nothing again. This time it was the .log file for the Config database. Open SQL Server Management Studio, right click the database in question, choose Task –> Shrink –> Files. This will give you the properties for the database, but because the default file shown will be the .mdf you have to pick “Log” from the File type drop down list:


Ensure “Release unused space” is selected and reclaim the missing GB.

by Andreas

HTML 5 video in Sharepoint 2010

For those who want video support in their Sharepoint site there’s finally a very easy way to do this that doesn’t depend on the Silverlight media player. It’s all done using HTML 5 and an excellent video player called VideoJS (

Pre-req: check my previos post about how to run HTML 5 in Sharepoint here. This part is required for it to work, and I am not covering it in this post.

Download the video-js-2.0.2 library (present version at the time of this post). There are three files of interest: demo.html, video.js and video-js.css.

1. View the demo.html file in your browser to verify that it works

2. Upload the .js and .css files to your Sharepoint site assets library (or wherever else you feel like storing it)

3. Open the source of the demo.html and copy the entire contents to your clipboard

4. Create a new Content Editor Webpart on your Sharepoint page, and open up the content HTML editor (this was also covered in that previous post). Paste in the demo.html source, and update the two source references to your asset files! You have to update both the .js and the .css. (My .js path was  <script src="/HTML5/SiteAssets/video.js").  Click OK.

5. How about that:


If you encounter any errors my guesses are:

1. You didnt alter the masterpage like i described in that previous post (you won’t get the link again!)

2. You are viewing your Sharepoint site in an OLD BROWSER (IE 9 required, or the latest version of Chrome, Safari or Firefox)

3. Your references to video.js and video-js.css are wrong. My site was called HTML5, and had a library called SiteAssets directly at the root level and gave me the path <script src="/HTML5/SiteAssets/video.js"

by Andreas

HTML 5 in Sharepoint 2010

Can it be done? Sure it can! But it requires a few minor adjustments..

1. Alter your master page to allow HTML5

Edit the masterpage of your site in Sharepoint Designer. Locate the following tag:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">

Simply remove everything behind “html” except the closing tag:

<!DOCTYPE html>


2. Remove forced IE 8 rendering

Your masterpage has a tag that pretty much says “Force this page to be rendered as an IE 8 browser would”. But IE 8 doesn’t support HTML 5 so get rid of it – delete the following line from your masterpage:

<meta http-equiv="X-UA-Compatible" content="IE=8"/>


3. Back in your Sharepoint site, add a new Content Editor webpart on the page where you want the magic of HTML 5 to be displayed. Open the HTML editor for the contents (you’ll find it up at the ribbon, looks a little something like this:



4. Put your HTML 5 code into the HTML Source window that appears, click OK and Bob’s your uncle!

by Andreas

Sharepoint 2007 / 2010 log file location

The default location for the Sharepoint (2007 / 2010) log files might make sense when you finally locate them, but remembering it at the time you need them the most is not that easy.

Sharepoint 2007 + log files + location =
C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12LOGS

Sharepoint 2010 + log files + location =
C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14LOGS

Now, when it comes to reading the bloody thing you’re on your own……..

by Andreas

Sharepoint Designer – Custom Item Style

So you’ve started messing around in Sharepoint Designer creating your own custom styles for some Content Query Web part (CQWP) by altering existing or adding new code to ItemStyle.xsl. You reach a point where you want to display a field that you don’t see in use anywhere else and you start wondering how to reference it. This tiny piece of code will actually print out a list of all the fields that are passed through and are available:

<xsl:template name="ListAllAvailableFields" match="Row[@Style='ListAllAvailableFields']" mode="itemstyle">
   <xsl:for-each select="@*">
       :: <xsl:value-of select="name()" /><br />

(Ensure you check in ItemStyle.xsl so the changes are reflected in your solution)

Open your CQWP in Edit mode, expand Presentation and change Item Style (under Style) to ListAllAvailableFields. Click Apply and you should now have a list of available fields printed neatly (..!) out for each list item.



These are the internal column names, and you can now reference any of them like this:

<div class="fancyLook">
    <xsl:value-of select="@MyCustomField" />

PS: the double colon ( :: ) in front of each field name is just added as a divider. Obviously this is not part of the name.

by Andreas

Sharepoint – use XSLT to define first element in CQWP

In a recent project I had the need for two Content Query Web Parts where one displayed the first 3 items from a list in a specific format, while the other had to display the remaining rows (from 4 and onwards) from the same list in a different format. Strangely enough I couldn’t find much useful information about this, but the solution was easy enough.

PS: For reasons not worth explaining, I solved this using two web parts but this could quickly be altered to be handled in a single CQWP.

The approach is to get the current row number, compare it to a value and decide whether or not to display the result. This was all done with XSLT in Sharepoint Designer.

1. Get the current row number

<xsl:variable name="RowNum" select="count(./preceding-sibling::*)" />

2. Add a simple IF statement to check if row number is higher than 3

<xsl:if test="$RowNum &gt; 3">
    <!-- whatever is in here will be rendered -->

I chose to use this to remove the first 3 elements of the result, but it can also be used to apply one style to the first X elements of a result and another style for the remaining elements.

There you have it, conditional filtering solved in Sharepoint Designer with OOTB functionality.

by Andreas

Sharepoint 2010 – Adding TaxonomyFieldControl to custom Page Layout

When attempting to add a taxonomy field control to your custom page layout, it will automatically be given a tag looking something similar to this:

<CustomTag_0:TaxonomyFieldControl FieldName="81d247d1-0373-4a2d-9e81-d4b69bf3e091" runat="server"></CustomTag_0:TaxonomyFieldControl>

When attempting to render this in Sharepoint Designer you’ll be told that “TagPrefix is not registered in this Web Form”:


If you’re one of those painfully optimistic characters you’ll still attempt to run it in the browser, which gives you the  ASP.NET error screen with the following message:

Parser Error Message: Unknown server tag ‘CustomTag_0:TaxonomyFieldControl”

For those who wants to dig even deeper than this, the following error message appears in the application event log:

Load control template file /_controltemplates/TaxonomyPicker.ascx failed: Could not load type ‘Microsoft.SharePoint.Portal.WebControls.TaxonomyPicker’ from assembly ‘Microsoft.SharePoint.Portal, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c’.


The solution is simple: just add a reference to the assembly which contains the Taxonomy Picker control at the top of your Page Layout:

<%@ Register Tagprefix="Taxonomy" Namespace="Microsoft.SharePoint.Taxonomy" Assembly="Microsoft.SharePoint.Taxonomy, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Then change the <CustomTag_0:TaxonomyFieldControl> to <Taxonomy:TaxonomyFieldControl> and off you go (remember there is a closing tag too, by the way..):

<Taxonomy:TaxonomyFieldControl FieldName="81d247d1-0373-4a2d-9e81-d4b69bf3e091" runat="server"></Taxonomy:TaxonomyFieldControl>