As I mentioned in my last post I'm upgrading some web parts. More notably, I'm moving from an unsigned assembly to a signed assembly. This presented me with an interesting problem.
If you upgrade a web part assembly, and the assembly is signed, you can force all the existing web parts that use that assembly to use the new version via the runtime element of the web.config file. You simply change the version number of your assembly, add it to SharePoint, and all your web parts get upgraded to the new version. Easy.
Okay, so what if your assembly was not signed and now it is? Good question. As far as I can tell the answer is that you are SOL. I tried every combination that I could think of and couldn't get it to work. Of course, since I'm an idiot so this doesn't mean much (as you can see this also isn't my first SharePoint hack :).
So what's a SharePoint hack to do? Hack, of course. First I put a couple of the old webparts onto a page, then ran a SQL trace and opened the page. From that trace I was able to figure out that there is a table called webparts (how original) that contained all the webparts for the page and what database this was in. I was also able to figure out the tp_webparttypeid for each of my old web parts. Next I added the new webparts to the page and went through the same process to get the tp_webparttypeid for each of my new webparts.
*** DISCLAIMER: DO NOT TRY THIS ***
Once I had the old and the new tp_webparttypeid I simple ran an update on the webparts table. I updated all the tp_webparttypeid to the new tp_webparttypeid where the webpart had the old id (that matched part for part in the assemblies). I really didn't expect it to work so I was very surprised when it did. It worked perfectly.
*** END DISCLAIMER ***
Okay so I've told you not to do this so don't blame if you try it and you break something. So far I've only tried it on my test machine which doesn't mean much. Tomorrow I'm planning on backing up our production database and then seeing if I can make this work on the production site. It will save us tons of time because as far as I can tell this is the only way to do this upgrade.
Now you can add one more hack to my list of SharePoint “resources” :)
Update: Well the upgrade went pretty smooth. There was one little glitch with the Xml Serialization namespace which I had somehow changed on a couple of the web parts. This meant the settings weren't showing up. So I changed them back, recompiled, uninstalled/installed the web parts and everything worked. Pretty cool! Not sure how else you could do this.