views:

1186

answers:

1

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?

+2  A: 

The problem is that the list is in another site.

It is possible to use the ListViewWebPart to reference a list from another site in the same site collection. You need to use the WebId property to do this. Here is a code example.

Another option is to use SharePoint Designer to create a Data View Web Part. This will allow you to use a list from another site or the SharePoint web serivces to pull data in. The results look similar to the list view web part and there is some powerful functionality you can use. This is the first blog post I found that demonstrates this, there should be several others.

Finally, you could use the Content Query Web Part. You probably know this one already and it is really more for displaying and not manipulating data.

Edited to remove incorrect information.

Alex Angas
ok, that's what I was afraid of.The thing is that I wanted to keep the "edit properites, view properties, send to,..." capability.Can I still have these kind of things using the Data View Web Part or it will require a lot of customization?thx in advance
It renders using an XSL transform (like the CQWP) so you get a lot of power there. However the out of the box stuff you're looking for will need some work or be impossible (I'm thinking 'Send To' for that) to do.
Alex Angas
I guess I'm going to look for a deeper customization or even a total custom interface to do that.thx for the information