Export (0) Print
Expand All

CbqQueryCache class

Caches the CbqQueryVersionInfo for a specified Content Query Web Part. This class cannot be inherited.

System.Object
  Microsoft.SharePoint.Publishing.CbqQueryCache

Namespace:  Microsoft.SharePoint.Publishing
Assembly:  Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)

[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class CbqQueryCache

Use the FetchCbqQueryInfoFromCache() method to instruct the Content Query Web Part to get the site, Web, page, or Web Part GUID and store it in the UserQueryVersionInfo property of this CbqQueryCache instance.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.Publishing;
using System.IO;

public partial class CBQCachePage : System.Web.UI.Page
{

    protected override void OnLoad(EventArgs e)
    {
        // For this to work the page has to have the "web", "page", and "wp" query parameters passed to it
        base.OnLoad(e);
        string webUrl = Request.QueryString["web"];
        Guid pageGuid = new Guid(Request.QueryString["page"]);
        Guid webpartGuid = new Guid(Request.QueryString["wp"]);

        CbqQueryVersionInfo queryVersionInfo = null;
        try
        {
            // Try and create a new CbqQueryCache and get the Query from it and display it on the page
            CbqQueryCache queryCache = new CbqQueryCache(this.Page.Cache, webUrl, pageGuid, webpartGuid, 120, Request.Url.Query);
            this.queryLabel.Text = queryCache.UserQueryVersionInfo.VersionCrossListQueryInfo.Query;
        }
        catch (InvalidOperationException)
        {
            queryVersionInfo = null;
        }
        catch (FileNotFoundException)
        {
            queryVersionInfo = null;
        }
        catch (ArgumentOutOfRangeException)
        {
            queryVersionInfo = null;
        }

        // User either has no rights
        // Or the web part does not exist
        if (queryVersionInfo == null)
        {
            Response.StatusCode = 404;
            Response.End();
        }
    }
}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);// Example 1{    string webUrl = Request.QueryString["webUrl"];    Guid pageGuid = new Guid(Request.QueryString["pageUniqueId"]);    Guid webpartGuid = new Guid(Request.QueryString["wpStorageKey"]);    int cacheFeedTime = 800;    // Retrieve Content Query Web Part information from the  cache.    CbqQueryCache queryCache = new CbqQueryCache(this.Page.Cache, webUrl, pageGuid, webpartGuid, cacheFeedTime);    // Execute Query    CbqQueryVersionInfo userCbqQuery = queryCache.UserQueryVersionInfo;    CrossListQueryCache xlqCache = new CrossListQueryCache(userCbqQuery.VersionCrossListQueryInfo);    DataTable data =  xlqCache.GetSiteData(SPContext.Current.Site);    // Perform ProcessData delegate that is specified on this web part    if (userCbqQuery.ProcessDataDelegate != null)    {        data = userCbqQuery.ProcessDataDelegate(data);    }    // Create a new Content Query Web Part.    ContentByQueryWebPart cbq = new ContentByQueryWebPart();    // Store the data in the new Content By Query Web Part.    cbq.Data = data;    panel.Controls.Add(cbq);}// Example 2{    string webUrl = Request.QueryString["webUrl"];    Guid pageGuid = new Guid(Request.QueryString["pageUniqueId"]);    Guid webpartGuid = new Guid(Request.QueryString["wpStorageKey"]);    int cacheFeedTime = 800;    // Retrieve Content By Query Web Part information from the cache.    CbqQueryCache query = new CbqQueryCache(this.Page.Cache, webUrl, pageGuid, webpartGuid, cacheFeedTime);    // Retrieve Information about the current user query.    CbqQueryVersionInfo userCbqQuery = query.UserQueryVersionInfo;    // Set Query Information on a new CBQ web part    ContentByQueryWebPart cbq = new ContentByQueryWebPart();    cbq.FeedTitle = userCbqQuery.FeedTitle;    cbq.FeedDescription = userCbqQuery.FeedDescription;    cbq.UseCopyUtil = userCbqQuery.UseCopyUtil;    cbq.DataColumnRenames = userCbqQuery.DataColumnRenames;    cbq.ProcessDataDelegate = userCbqQuery.ProcessDataDelegate;    CrossListQueryInfo crossListInfo = userCbqQuery.VersionCrossListQueryInfo;    cbq.QueryOverride = crossListInfo.Query;    cbq.WebsOverride = crossListInfo.Webs;    cbq.ViewFieldsOverride = crossListInfo.ViewFields;    cbq.UseCache = crossListInfo.UseCache;    cbq.WebUrl = crossListInfo.WebUrl;    if (crossListInfo.RowLimit == uint.MaxValue)    {        cbq.ItemLimit = -1;    }    else    {        cbq.ItemLimit = (int)crossListInfo.RowLimit;    }    // The List Override takes a string.Format. Therefore, you must encode { and } before passing it back.    string listOverride = crossListInfo.Lists;    listOverride = listOverride.Replace("{", "{{");    listOverride = listOverride.Replace("}", "}}");    cbq.ListsOverride = listOverride;    // Set items that may affect Audience Targetting.    cbq.ShowUntargetedItems = crossListInfo.ShowUntargetedItems;    cbq.FilterByAudience = crossListInfo.FilterByAudience;    if (crossListInfo.GroupByAudience)    {        cbq.GroupBy = "{" + FieldId.AudienceTargeting.ToString() + "}";    }    if (crossListInfo.GroupByAscending)    {        cbq.GroupByDirection = ContentByQueryWebPart.SortDirection.Asc;    }    panel.Controls.Add(cbq);}      }

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft