The list view web part are used by SharePoint to list and library data. When a new list is created, the web part for the list is also created automatically.List view web parts can show one view at a time from the list or library to which it is pointing.

How can i replace this with a special Web Part (My Web Part get ListID,ViewID and show one view from the list or library)?

I mean that:When a new list is created, my web part for the list is also created automatically.

1 Answer 1


I don't think you can prevent the OOTB List entry from showing up, but you should be able to add your own web part by responding to the ListAdded event and then add a .webpart file with the right configuration to the _catalogs/wp documentlibrary.

You probably then also want to remove it on ListDeleted

To add a webpart to a page inside the ListAdded use code like this:

using (var manager = web.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared))
  var webPart = new MyWebPart();
  webPart.ListID = xxx;
  manager.AddWebPart(webPart, zoneID, zoneIndex);
  • Thanks. in ListAdded event, Mywebpart should add to special page ? Please explain more. :)
    – ar.gorgin
    Commented Apr 8, 2012 at 9:08
  • If you want your webpart automatically added to a page you can do that using a SPLimitedWebPartManager, but if you just want it to show up as a webpart to be added then you should add the right xml file with extension .xml to _catalogs/wp Commented Apr 8, 2012 at 9:43
  • I want it automatically added to a page , when list added . my webpart have a spgridview and get list id then binding spgridview .
    – ar.gorgin
    Commented Apr 19, 2012 at 5:55
  • Thanks a lot , but how do new mywebpart(how do use mywebpart?)
    – ar.gorgin
    Commented May 2, 2012 at 8:53
  • The MyWePart is the Web Part you created, so you should set the properties you need. This code only adds the web part to the page as if it was done by the user adding it through the UI and setting the properties. Commented May 2, 2012 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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