The following example code demonstrates one way to use the CrossListQueryCache object, properties, and methods. This code views data in the CrossListQueryCache object, gets the data, and stores the data in a new Content Query Web Part for viewing.
using System;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections.Generic;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.ApplicationPages;
using Microsoft.SharePoint.Publishing.WebControls;
using Microsoft.SharePoint.Publishing;
namespace CodeSampleNamespace
{
public class CodeSample : LayoutsPageBase
{
protected System.Web.UI.WebControls.Panel panel;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// CrossListQueryExample
{
CrossListQueryInfo crossListInfo = new CrossListQueryInfo();
crossListInfo.ViewFields = "<FieldRef Name=\"Title\" Nullable=\"True\" Type=\"Text\"/><FieldRef Name=\"FileRef\"/>";
crossListInfo.Query = "<Where><And><Eq><FieldRef Name=\"File_x0020_Type\"/><Value Type=\"Text\">aspx</Value></Eq>" +
"<Neq><FieldRef Name=\"ContentType\"/><Value Type=\"String\">Article Page</Value></Neq></And></Where>" +
"<OrderBy><FieldRef Name=\"Created\" Type=\"DateTime\" Ascending=\"True\"/></OrderBy>";
crossListInfo.RowLimit = 15;
crossListInfo.Webs = "<Webs Scope=\"Recursive\" />";
crossListInfo.Lists = "<Lists ServerTemplate=\"850\">";
crossListInfo.WebUrl = "/";
CrossListQueryCache xlqCache = new CrossListQueryCache(crossListInfo);
DataTable results = xlqCache.GetSiteData(SPContext.Current.Site);
// Store the data in a new Content Query Web Part to display the results.
ContentByQueryWebPart cbq = new ContentByQueryWebPart();
cbq.Data = results;
panel.Controls.Add(cbq);
}
}
}
}