SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to programmatically add a CEWP to a list (to perform operations on my list forms), it's very easy to do it through the SP interface but I can't manage to reach the webpartmanager of my list with the code...

Thank you by advance

share|improve this question
up vote 1 down vote accepted

Your list does not contain a webpart manager. Your pages contain a webpart manager. Luckily the disp/edit forms are pages in your "list folder".

That means you should be able to open the desired list form in a webpart manager:

var editFormUrl = listUrl + "/Forms/EditForm.aspx";
var wpm = web.GetLimitedWebPartManager( editFormUrl, PersonalizationScope.Shared );
wpm.AddWebPart( new YourCustomWebPart(), "Main", 0 );

That should give you a webpart manager for the Edit Form in a document library and add a webpart named YourCustomWebPart to it (regular lists lack the /Forms/ part of the url, so for those lists, just remove it).

FYI: List forms contains only one webpart zone named "Main", and it already has a webpart of type ListFormWebPart in it. This is the webpart that shows you the list item data.

I have not tested manipulating these forms this way, so I do not know if this actually works, but this is how you work with the SPLimitedWebPartManager anyway :).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.