Tuesday, August 17, 2010

ListView from other site collection

Scenario:
ListView Webpart and new XsltListViewWebpart are great new controls to display list/library information from with in the sub-site.

But we had a little bit different requirement. As we wanted to display list views from other site collection / sub-site.

Solution:
For control List is a list , as long as we can code it and bind it to right control.

Few options we tried/thought of

1. Create a new Datatable and load it with view items and then using SPGridView bind it. ( Good 30-40 lines of code )

2. Create a new SPDataSource pointing to right list id and bind it to SPGridView.
( 10-15 lines of code )

3. Create a ListViewWebpart and point the ListId and ViewGuidId property to right values. ( 10-15 lines of code )

4. Create a XsltListViewWebpart and point the ListId and ViewGuidId property to right values. ( 10-15 lines of code )

5. How about get right SPView and render it with 2 line. I am still showing from same site collection but you can create a new object from other site collection and do the same. See below

Code:

 protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
writer.Write(SPContext.Current.Web.Lists["Tasks"].DefaultView.RenderAsHtml());
}
CRUX of the post is RenderAsHtml is AWESOME :)

2 comments:

MadanKamuju September 3, 2010 at 8:13 AM  

We have one require ment as mentioned in this thread but i dont have option of using code. I have only one option using UI means we dont have central administration permission and i am using the client only. Is ther any other way to achieve this functionality?

Sandeep K Nahta September 3, 2010 at 11:19 PM  

There is a way.. u can use SPD and XsltListView I think.


http://www.endusersharepoint.com/2010/04/06/sharepoint-reproducing-a-roll-up-dataviewwebpart-in-another-web/