Upgrading webparts with new codebase

While upgrading a SharePoint 2007 site to SharePoint 2010, we decided we’d take the opportunity to clean up our project (organize the namespaces better, cut down on number of projects in the solution, etc). Being that its a internal test project, the risk was rather low. The problem with doing this is that SharePoint keeps references of assembly fullnames and types in the content database so that if you change the name of your dll’s and/or namespaces in your code, webparts will stop working on existing content.

Assembly redirects will only get you so far and only work if the assembly name stays the same.
In our case, we had OldAssembly.One.dll, OldAssembly.Two.dll, etc which got merged into NewCleanAssembly.dll.

So I wrote a utility to remap assemblies in the content database. Basically it allows you to load in old assemblies, view which of the classes are referenced by SharePoint and remap them to new assemblies.
Also, it will go into the properties of all webpart instances and remap old values to corresponding new ones in the new assembly.

It does this by generating new type IDs for the new assemblies and classes and deserializing the webpart properties, serializing it back after fixing the values and then write the whole thing back to the database.
The three fields that are updated are: tp_WebPartTypeID, tp_AllUsersProperties and tp_PerUserProperties in the AllWebParts table.

(The remaps in the above screenshot is for demonstration only, obviously we didn’t remap SharePoint’s own assemblies)

Now, this is highly unsupported and I wouldn’t recommend you do it in a production environment. Microsoft does not support any modifications done directly in the SharePoint database as far as I know.

… but it worked perfectly 🙂

I might post the tool on codeplex if anyone is interested.

Advertisements

4 Responses to Upgrading webparts with new codebase

  1. Hugo Scaramal says:

    Hi Frode, I would greatelly appreciate if you could share this tool, or even share the code behind it.
    I´m stucked where I´m trying to replace a RAD Editor web part with the standard Sharepoint 2010 Content Editor webpart, and it seems your tool could do the same.
    What I´m trying to do is deserialize the tp_PerUserProperties / tp_AllUsersProperties and write it back with the content and properties of a default content editor webpart.
    Not sure if it´s going to work, but worth a trial.
    Any help would be very much welcome!
    Btw, great work!

    • Frode Hus says:

      I’m not entirely sure this approach will help you. Are you trying to switch out the RAD editor with the basic content editor on numerous pages in a site or just one?
      My tool is made to update assembly references for a webpart that has its namespace and such changed and while you could use it to switch out the webpart for another, but it won’t create a new set of webpart properties.
      What it does is update type values in the webpart properties to reflect namespace changes.

      However, it’s an interesting thought – so I think I’ll clean up the tool and post it on CodePlex.
      You should be aware, though, that doing this kind of change directly in the database will void any support you have with Microsoft for your SharePoint farm.

  2. Hugo Scaramal says:

    Sorry for the leck of information. And, yes, I´m trying to replace the RAD webpart in all pages it is being used in our farm.

    One of your comments was:
    “Also, it will go into the properties of all webpart instances and remap old values to corresponding new ones in the new assembly”.

    So I thought you could be changing values in the fields tp_AllUsersProperties and tp_PerUserProperties. I was wondering how did you do it.

    I was messing with the properties fields to figure out how to read/write, I think I´m close, but still not there yet.
    This post helped me a bit:
    http://endersoft.blogspot.com/2008/01/some-sharepoint-stuff.html

    By the way, I´m aware of terms on microsoft support and all that. I will take the risk! 🙂

    Thanks a lot for your help!

    • Frode Hus says:

      I just added a new post with a bit more information about the webpart properties, have a look at that and see if it answers some of your questions 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: