I have created a Codeplex for this : http://webpartreplacer.codeplex.com The next versions will be uploaded there soon !!!
Basically, How does it work? On a specific application, I try to load the assembly that contains the webparts (source and destination) using reflection :
Then I look inside the Default page of each web and subweb trying to find the webpart (by checking the type of each webparts on the page) and if I find it, I replace the webpart using the SPLimitedWebPartManager.
I know that I should also parse all the document libraries to find other webpart pages in order to parse them as well... But in my current project, it wasn't a need, and I was kind of lazy!
Below is the iteration how I check whether the webparts on the page are to be replaced.
This is the part 1 of the replacement. Now let's say that we want to go futher. Why not trying to specify some properties on this new webpart?
OK, I have created a ObjectCollection object containing a list of KeyValuePair
Then before the AddWebPart([...]) code line, I have added the following code :
What happens here? We just try to get The property we try to set contained in our newly instanced WebPart. If found, we try to Use the Parse method of this property (Yes this only work with simple types (as Int32, Bool, String), and then we invoke it! Simple!!
That's it. You just have to make an iteration on each SPSite of you application and here we are!
Once again, be aware that this code only checks the default.aspx page !!
Sorry for that!!
Go to check in the codeplex project.