Tuesday, March 15, 2011

List does not exist error


While adding a new list view web part to a homepage , stuck with the following exception.
List does not exist The page you selected contains a list that does not exist. It may have been deleted by another user.
After some fiddling, found Web.Id for a LVWP is required to resolve this issue. After providing the WebId for the ListViewWebPart, web part adds to the page perfectly.

ListViewWebPart lvp = new ListViewWebPart();
lvp.ListName = Web.Lists["Tasks"].ID.ToString("B").ToUpper()  ;
lvp.ZoneID = "Center";
lvp.Title = "Tasks List";
lvp.WebId = Web.ID;  
SPFile homePage = Web.GetFile("default.aspx");
SPLimitedWebPartManager webmngr = homePage.GetLimitedWebPartManager (PersonalizationScope. Shared);
webmngr.AddWebPart(lvp, "Center", 3);
webmngr.SaveChanges(lvp);

Happy SharePointing :)

2 comments:

Anonymous said...

Thanks for the Post. I am pretty new to SP and was wondering where I would go to change what you mentioned here. It does not look like SP Designer.

Aravind said...

It is not SP designer, It is on SharePoint object model code.