SharePoint 2010: Cross Site List and XsltListViewWebPart

I been working on a project recently and one of the pages required a list view from another site from the same site collection. So this is what I had to do to make it work.

var site = SPContext.Current.Site;
var spList = site.AllWeb["yourwebsite"].Lists["listname"];
var xsltLvWp = new XsltListViewWebPart(){
    Title = "My Cross Site List View",
    WebId = spList.ParentWeb.ID,
    ListName = spList.ID.ToString("B").ToUpper(),
    ListId = spList.ID,
    ViewGuid = spList.Views["View Name"].ID.ToString("B").ToUpper()
}

Binding SPList to Binding Controls.

To bind a SPList to a binding control list for example the DetailsView data control you will need to provide a DataSource to it. The problem is SPList doesn’t implment the IDataSource interface, but I have discovered that there is a SPDataSource which allows you to pass a SPList object as a parameter in the constructor. Below is a code

var spList = SPContext.Current.Web.Lists["List Name"];
var ds = new SPDataSource(spList);
DetailsView1.DataSource = ds;
DetailsView1.DataBind();

Deploying Assembly Files With Your Sharepoint Solution

Recently I have been working on a Sharepoint 2010  and I had created a Class Library project that will contain some classes and methods. One of the custom webparts I had created was calling a method from one of the class, but when I press F5 to deploy and test my web part I got an error and my assembly file was missing in Sharepoint. I realised that my Class Library assembly file was not deployed. 

Below is a simple step by step instruction on how to include a assembly file in your Sharepoint package.

For example here I have a solution with a Sharepoint 2010 and a class library project. In the Sharepoint 2010 project there is a package folder containing a file called Package.package

visual studio 2010 solution

(more…)

Shares