Usually we add/update/delete web parts in the publishing page in MOSS 2007 by SPLimitedWebPartManager in object module. Most of the time, we got the test/demo small console program, then we implemented into QA/Staging/Production environment and got the expected result. But sometime not, and will confused us for a long time…
Recently, I am trying to add web part by object model, I choice the way to create web part instance and add the web part into PublishingPage by SPLimitedWebPartManager. The reason is the web part adding execute dll (thread) will called by the web part. So the only way to create new web part instance is by Reflection.
But I always got error message told me the page don’t check out? why? I run Page.Checkout() several time, and the web part adding was not work still. The error message is
The file is not checked out, You must first check out this document before making changes. at Microsoft.SharePoint.Library.SPRequestInternalClass.AddWebPart
After two weeks, finally I got the hint in this discussion thread. Yes, the point is
PLEASE INITIAL SPLimitedWebPartManager AFTER Page Checkout.