Error on theme page post SharePoint 2010 upgrade

July 29, 2011

I recently upgraded a MOSS 2007 site to SharePoint Server 2010 which seemed to go relatively smoothly, however a short while after the upgrade a user reported they got an error when trying to set the theme on a new site.

When I checked this was indeed the case i got an object reference not set to an instance of an object error, see full error below. I spent some time looking into this and researching information online and I was able to establish the error was down to the fact that the theme gallery had not been created in the upgraded site.

I found some articles, see below, that seemed to deal with the same issue and while I found the information useful it didn’t supply instructions on how this could be achieved hence why I decided to document the steps I performed to correct this.

From looking at the articles above the options were to re-create the theme gallery or redo the upgrade. Realistically redoing the upgrade was not an option so this left me with trying to either move the theme gallery from another site collection or recreating it.

My first though was this was something I could do through SharePoint Designer so I opened a test SharePoint 2010 site and tried to export the themes list but quickly found this was not possible.

My next attempt was to try and copy from one SharePoint Designer instance to another. To do this I created a test site collection on the production environment and opened this in SharePoint Designer. With two SharePoint Designer windows open side by side I tried to copy the theme gallery from the test site and paste it into the upgraded site. This partially worked but it re-created it as a folder not a list so while I could browse to the URL it didn’t recognise it as a list.

Next I tried copying the theme gallery as a list template and re-create it using this. I navigated to the theme gallery on my test site collection and went to the settings but found there is no save list as a template option on this list. I got around this by getting the list ID of the theme gallery and then going to save another list and clicking save as a template. In the new screen I then replaced the list ID in the query string with the theme gallery list ID. This then allowed me to save the gallery as a template and I could see it in the list gallery. When I then went to create a new list I found the template I saved was not available. Thinking about it this made perfect sense as the default theme gallery list definition is mark as hidden so any new templates created using this type of list would also be hidden.

The solution that finally work was to create a new list through the UI but change the URL to supply the out of the box theme gallery list template ID. From research online I was able to identify that the theme gallery template ID was 123 so I went to the root of my site and created a list as normal but I then changed the URL removing the feature ID and changed the ListTemplate querystring parameter to 123. I entered the list name as theme and clicked ok. This created my list as expected but it was still in the wrong location. In order for the theme functionality to work the list had to be under the catalogs folder. To move the list I opened SharePoint Designer and simply dragged the list to where it should be. At this point I could now use the set theme functionality but there were no items so once again I opened my test site collection in SharePoint Designer and copied all the themes across to my upgrade site. When I then refreshed the choose theme page it worked and all the themes were available to choose from.


Being a developer normally I don’t use SharePoint Designer, however in this case I found it extremely useful to be able to move and manipulate objects in the SharePoint site.

Hopefully other people will find this useful, however please ensure if there is anything you are not sure of try it on a development environment first and always ensure you have a back up you can revert to before stating any work.

Full Error Details

Exception information:
    Exception type: NullReferenceException
    Exception message: Object reference not set to an instance of an object.
Thread information:
    Thread ID: 9
    Thread account name: DomainOurAccount
    Is impersonating: False
    Stack trace:    at Microsoft.SharePoint.ApplicationPages.ThemeWebForm.<>c__DisplayClass2.<LoadV4Page>b__0()
   at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2()
   at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
   at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
   at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
   at Microsoft.SharePoint.ApplicationPages.ThemeWebForm.LoadV4Page()
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


Creating button shortcuts in Windows Forms Applications

July 22, 2011

I recently created a Windows Forms Application and some of the feedback from users was they would like to have some shortcuts for certain buttons. At first I just assumed this was easy enough but when I started looking into it I realised there didn’t appear to be any out of the box functionality that would do this.

As I’m sure most people do I turned to Google and found that there wasn’t a way to handle this with out custom code. At first I looked at using the KeyDown event on the form but this didn’t quite work as expected so I managed to find an another article which suggested overriding the ProcessCmdKey method. I tried this and like magic it works, see code below.

To be honest I would expect this functionality to work without the need to write custom code but there isn’t much to it so its not too bad.


Code Snippet
  1. protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
  2.         {
  3.             switch(keyData)
  4.             {                
  5.                 case (Keys.Control | Keys.N):
  6.                     BtnTest1_Click(null, null);
  7.                     break;
  8.                 case (Keys.Control | Keys.S):
  9.                     BtnTest2_Click(null, null);
  10.                     break;
  11.                 case (Keys.Control | Keys.F):
  12.                     BtnTest3_Click(null, null);
  13.                     break;
  14.                 case (Keys.Control | Keys.G):
  15.                     BtnTest4_Click(null, null);
  16.                     break;
  17.                 case (Keys.Control | Keys.P):
  18.                     BtnTest5_Click(null, null);
  19.                     break;
  20.             }
  22.             return base.ProcessCmdKey(ref msg, keyData);
  23.         }

Display Form Error Post SharePoint 2007 to SharePoint 2010 Upgrade

July 19, 2011

My last project I worked on upgrading a MOSS 2007 site to SharePoint Server 2010 and while the vast majority of the site works as expected there were certain occasions when I click on an item in a list I got the standard SharePoint error screen saying an error occurred. As per normal this is not helpful in the slightest, however when I checked the log I noticed the error below.

System.Web.HttpException: Cannot find ContentPlaceHolder ‘PlaceHolderUtilityContent’ in the master page ‘~masterurl/default.master’, verify content control’s ContentPlaceHolderID attribute in the content page. at System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) at System.Web.UI.Page.get_Master() at System.Web.UI.Page.ApplyMasterPage() at System.Web.UI.Page.PerformPreInit() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Post upgrade I was still running in the SharePoint 2007 UI using some custom masterpages so I just figured another Content Placeholder was required in SharePoint 2010 so I added the line below to each of my custom masterpages and it started working.

<asp:ContentPlaceHolder id="PlaceHolderUtilityContent" runat="server" />

Display cropped command line information

July 14, 2011

When running an stsadm command I was getting lots of results returned so much so when I scrolled up to the top I couldn’t get to all the results. This is down to the Screen Buffer Size property on the window’s properties. You can change this by following the steps below:

  1. Open the command line window, if you are doing this in Windows Server 2008 then you may need to run this as an administrator.
  2. Click n the top level corner and selecting properties from the drop down list
  3. In the new window select the layout tab
  4. Increase the Screen Buffer Size limit (This took me a while to get the right figure but you could always bump it up run the command and lower again)
  5. Click ok
  6. Re-run your command

MOSS 2007 to SharePoint Server 2010 Upgrade Part 1

July 11, 2011

I have just finished a project to upgrade a client from MOSS 2007 to SharePoint Server 2010 and I want to share the process I used and the resource I found useful so it may provide a starting point to anyone else you needs to upgrade their system.

The best place I found for information was, as you would expect, the technet site for SharePoint 2010. From there you can find a whole raft of information on best practices, suggested approaches, things to consider and it really helped me formulate my approach but also justify it to the stakeholders involved in the project.


After reviewing the clients current setup one of the first things I noticed was they hadn’t installed service pack 1 or 2 so I knew this was the first thing I had to address.

From experience I know it is never advisable to install services packs directly onto live servers and this presented the first issue as there was no representative development environment which I could use to test the updates. After discussing this with some of our infrastructure team we decided to take a copy of the existing servers and place them into a virtual environment. This would then be placed in a private network thus giving me a duplicate environment that was isolated from the network.

Once I had tested the virtualised environment was up and running I then took a snapshot of the servers so I could return to the pre-service pack state at a later date. I then proceed to install both service pack 1 and 2. To help with this I found some very useful articles by Shane Young on How to install WSS and MOSS SP1 and Install Guide: SP2 for SharePoint (WSS v3 and MOSS 2007). All this was done with a recent copy of the content database in order to establish if the updates would cause any issues.

On a date agreed with the client the virtual servers were rolled back to the pre-service pack state. I then marked the live content database as read only so the client could still access the system but couldn’t update the content while the service pack updates were installed on the virtual environment. Just to ensure users could access the system but not update it I performed a series of tests trying to add items to lists and document libraries. Once I was happy with this I then backed up the SharePoint content database and copied it across to the virtual database server and restored it. At this point I encountered a variety of issues from the time it took to back up the database to the the time it took to transfer across the network. The biggest issue for me was being able to get the database back up file into the virtualised database server. As I mentioned we had set up the virtual environment in a private network which meant we couldn’t easily copy/move files onto the virtual servers. In the end the only solution was to have another server in the main network copy the database file to this then join the server to the private network.

After the service packs were installed and the site had been tested by both myself and the client the old servers were switched off and the new virtual ones added to the network.

This may seem like a lot of work but it gave me the ability to test without affecting the live system and provided some reassurance to the client as they were able to test the system before it went live.

Lessons Learned

One of the biggest lessons I learned from this was to allow time in the project plan for copying of the data from one environment to another. In this project the client’s intranet was just over 50GB and what I forgot to factor was the time it would take to back this up and copy it from the old servers to the new ones.

Next Steps

In my next article I will discuss the steps I followed to upgrade the site to SharePoint Server 2010 using the content DB attach upgrade method.

Allow Users to add rows in Data Grid View

July 7, 2011

While working on a project that required me to create a Windows Forms Application I was binding a list of order objects to a Data Grid View but I also wanted users to be able to add items as well. Initially I thought this would be easy I simply set the AllowUsersToAddRows property on the Data Grid View to true, however when I ran the application this didn’t do anything.

I spent some time investigating this and found that you have to create BindingSource object and set the AlloNew property to true and then it adds an extra row where users can add data, see full code below.

Code Snippet
  1. BindingSource source = new BindingSource();
  2.                     source.AllowNew = true;
  3.                     source.DataSource = order.OrderLines.Line.ToList();
  5.                     DgvOrder_OrderLines.DataSource = source;

Launching Windows Forms Applications from within an existing Windows Forms Application

July 7, 2011

My most recent project has been to develop a Windows Forms Application that connections to Microsoft Dynamics NAV system. I have been working closely with a NAV specialist who has been exposing some web services I can then use to develop the application.

The application has to be able to perform a variety of tasks and operations so I have separated these out into different tabs to make the interface more intuitive and less cluttered. My problem came when I needed to get a users to select an item from a drop down list when they clicked on a submit button. Normally I could add a panel and then hide this until the user pressed the button but given the amount of information on some forms I decided this would not be a good idea.

My next thought was it would be nice if I could re-use the MessageBox functionality and add a drop down list on this but after some research online I soon learned that this was not possible. I did find some posts about creating a class based on the MessageBox functionality and extending this but that seemed like a waste of time and effort.

I then spent some time researching other options and was surprised to learn how easy it is to call another Windows Forms Application in an already running Windows Forms Application and get some data from it, see example code below.

Launch the new Form
  1. string orderPadNo = String.Empty;
  2.             OrderPad orderPadForm = new OrderPad(customerNumber);
  3.             try
  4.             {
  5.                 // Show select order pads Form as a modal dialog and determine if DialogResult = OK.
  6.                 if (orderPadForm.ShowDialog(this) == DialogResult.OK)
  7.                 {
  8.                     // Read the contents of select order pads combobox
  9.                     ComboBox cbxOrderPads = (ComboBox)orderPadForm.Controls["CbxOrderPad_OrderPads"];
  10.                     if (cbxOrderPads != null)
  11.                     {
  12.                         orderPadNo = cbxOrderPads.SelectedValue as string;
  13.                     }
  14.                 }
  15.             }
  16.             finally
  17.             {
  18.                 if (orderPadForm != null)
  19.                 {
  20.                     orderPadForm.Dispose();
  21.                 }
  22.             }

In my new Windows Forms Application I then have the required functionality/display and two buttons. One button confirms the users selection and the other is for cancelling out of the interface. I have included the code below to return out of the new Windows Forms Application.

Code Snippet
  1. private void BtSelectOrderPad_Cancel_Click(object sender, EventArgs e)
  2.         {
  3.             this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  4.         }
  6.         private void BtSelectOrderPad_Ok_Click(object sender, EventArgs e)
  7.         {
  8.             if (CbxOrderPad_OrderPads.SelectedValue == null || String.IsNullOrEmpty(CbxOrderPad_OrderPads.SelectedValue as string))
  9.             {
  10.                 MessageBox.Show("Please select an order pad");
  11.                 return;
  12.             }
  14.             this.DialogResult = System.Windows.Forms.DialogResult.OK;
  15.         }

%d bloggers like this: