SharePoint 2007 to 2010 Migration Issue: Event Content Type

While reviewing our recently migrated SharePoint 2010 environment a user noticed an issue with an events list.  While trying to change the column ordering for the event content type assigned to the list he saw that the category field was listed twice.   Also, when he tried to add a new item to the events list he was shown two separate dropdown lists with the title of category.

Using SharePoint Manager 2010 I took a look at the object model and properties for the events list.  I noticed that under the event content type associated with the list the field category was in fact displayed twice. 

My next step was to write a small custom c# console application that could write out the name and ID of the fields being used on the list.  (This could also be done using PowerShell) 

First I started by enumerating the .fields property on the list itself.   There I saw only a single category field listed.   Next I modified the application to show the fields associated with lists “event” content type.   This time I saw 2 fields returned with the name category.   I compared the GUIDs returned for the 2 fields to the one field returned from the list’s .fields property.   I saw that one of the GUIDs matched and the other did not.    At this moment I made the assumption that the category field with the GUID that didn’t match was causing the problem.

Once again I made modifications to the console application.  This time I had the application automatically detect the bad category field and then delete it from the content type definition.   Below is the code that I used to accomplish this task:

using (SPSite site = new SPSite(http://mysite))
{
    using (SPWeb web = site.OpenWeb())
    {

        SPList eventList = web.Lists["Events"];
        Guid badFieldID = Guid.Empty;
        Guid goodFieldID = Guid.Empty;

        Console.WriteLine("– List –");
        foreach (SPField fld in eventList.Fields)
        {
            if (fld.Title == "Category")
            {
                Console.WriteLine(fld.Id);
                goodFieldID = fld.Id;
            }
        }

        Console.WriteLine("– Content Type –");
        SPContentType ct = web.ContentTypes["Event"];
        foreach (SPFieldLink fl in  eventList.ContentTypes["Event"].FieldLinks)
        {
            if (fl.Name == "Category")
            {
                Console.WriteLine(fl.Name + " " + fl.Id.ToString());
                if (fl.Id != goodFieldID)
                {
                    badFieldID = fl.Id;
                    Console.WriteLine("  ^^^ BAD FIELD ^^^");
                }
            }
        }

        if (badFieldID != Guid.Empty)
        {
            eventList.ContentTypes["Event"].FieldLinks.Delete(badFieldID);
            eventList.ContentTypes["Event"].Update();
            Console.WriteLine("Delete field " + badFieldID.ToString());
        }

    }
}

The events list began working properly with only one category field once I ran the final version of my console application.

I am not sure what occurred during the migration from SharePoint 2007 to 2010 that caused this problem.  I verified on the original 2007 farm that there wasn’t any duplicate fields in the event content type.   I also have been able to reproduce this exact issue multiple times on different farms by doing a database attach migration.   So far this is the only events list that I have found that experienced this problem.

Please leave a comment if you have also run into a similar issue after a SharePoint 2007 to 2010 upgrade / migration.  I would like to hear about your specific situation.

3 thoughts on “SharePoint 2007 to 2010 Migration Issue: Event Content Type”

  1. I had this same issue in testing our 2010 migration. I converted your code to powershell and it fixed my issue also.

    Thanks!

  2. I discovered the issue in a different manner. My office has a calendar to which entries are added from several other calendars, our “Combined Calendar.” These calendars all have a custom field, “Branch.”

    All “Branch A” calendar entries were incorrectly moved to the “Branch B” calendar/list. I believe the custom field was changed from A to B, as well (this was several weeks ago, so I don’t recall for certain). I moved the entries back to the “Branch A” calendar/list and most likely reverted the custom field values from B to A.

    So now, the Combined Calendar shows one Branch field in the datasheet or modify-view modes, but when you add an entry, the Branch field appears, twice. When I go to List Settings/(content type)Event/Column Order, I can see a second “Branch” field at the bottom of the list of columns.

    I read about a workaround, whereby you can change the column order to make the duplicate column disappear. I tried it, and the duplicate column always reverts to the bottom of the list.

    Unfortunately, I’m more of an occasional, cut-and-paste coder, for now, with no license for Visual Studio–probably a good thing, given my experience level–so an out-of-the-box or SPD solution is needed.

    On a related note, any tips for ramping up on SharePoint development for a coding amatuer (lots of experience with HTML/CSS, limited experience with a wide variety of programming languages) would appreciated.

Leave a Reply