I cannot show the content of a document library using a list view contained in a web part located on my root web application.
Here is the site structure:
main_site subsite1 Shared Documents subsite2 Shared Documents
My webpart is located on the main_site
.
In this webpart, I have a Sharepoint ListViewWebPart in which I want to show the Shared Documents from subsite1
for instance, but it does not seem to work. I get the following error:
List does not exist
The page you selected contains a list that does not exist. It may have been deleted by another user.
What is odd is that when I debug, I can see that the SPList is correctly initialized and contains the element of my list. However at the line Controls.Add(mylistview)
, I get the error.
Here is the code I use to bind the list to my ListView:
SPList list = SPContext.Current.Site.AllWebs["subsite1"].Lists["Shared Documents"];
ListView lv = new ListView();
lv.ListId = list.ID.ToString();
lv.ViewId = list.DefaultView.ID.ToString();
lv.DataBind();
this.Controls.Add(lv);
Does someone have a logical explaination and solution to this problem?