About SPLimitedWebPartManager

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.


Anonymous said...

Thank You so much for this small snippet, I was looking over the link you sent and did not even see the mistake. Worked first time once I checked out the page before any of the code ran. Thank you very much once again.

price per head said...

Thank you for sharing to us.there are many person searching about that now they will find enough resources by your post.I would like to join your blog anyway so please continue sharing with us