Thursday, April 14, 2011

Sharepoint 2010 Rename Assembly of WebPart

I came across of a new issue in SharePoint 2010 today. My client wished the web parts assembly name changed from some name A to some name B.
Well I thought easy, rebuild the web part, verify that the web part file is correct, retract old solution, deploy new solution (Web part is deployed as feature).
Well... When I inserted the web part with the new name everything worked. but all the pages that had the web part already inserted stopped working, saying that the type was not found.
The old web parts where trying to load the old assembly.
After looking and "googling" I didn't find any solution.. So my last resource... change the entry on the Content DB.  Here is the script

UPDATE
[SiteCollection_Content_DB].[dbo].[AllWebParts]SET [tp_WebPartTypeId] ='NewWebPartTypeId',[tp_Assembly] = 'NewAssemblyBaseNamespace, Version=NewVersion, Culture=neutral, PublicKeyToken=newtoken',[tp_Class] = 'NewCompleteClassNameWithNamespace'
[tp_Class]
WHERE [tp_Assembly] = 'OldAssemblyBaseNamespace, Version=OldVersion, Culture=neutral, PublicKeyToken=oldtoken' and = 'OldCompleteClassNameWithNamespace' and[tp_WebPartTypeId] ='OldWebPartTypeId'
To  know the new values I just inserted one web part with the new dll and copied the values form the record I found on the AllWebParts table .


I strongly recommend though to make a backup of your DB!
I actually never touch the DB of SharePoint. I even convinced my client not to change the Assembly name... But still I tried the script in my Dev environment and it seemed to work.




UPDATE: Wow.. why do it the Unsupported way!... there is the supported way: Open your webApplication, loop through all of your sites & webs. Open each page, check if the webpart's in it, if so get the position(s) of the current web part(s). remove it (them) and insert the new webpart(s) with the new definition in the position(s) fetched.
 

No comments:

Post a Comment