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.


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);
| improve this answer | |
  • Thanks. in ListAdded event, Mywebpart should add to special page ? Please explain more. :) – ar.gorgin Apr 8 '12 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 – Per Jakobsen Apr 8 '12 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 Apr 19 '12 at 5:55
  • Thanks a lot , but how do new mywebpart(how do use mywebpart?) – ar.gorgin May 2 '12 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. – Per Jakobsen May 2 '12 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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