PublicationCriteria (ASP.NET)

The following is an example of using the PublicationCriteria and AndCriteria to query the broker storage for a specific Publication:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Tridion.ContentDelivery.DynamicContent.Query;
using Tridion.ContentDelivery.DynamicContent;

namespace TestTaxonomies
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            // Create query
            string strTaxURI = "tcm:4-7-512";
            string strComponentTemplateURI = "tcm:4-17-32";
            int iPublicationID = 4;

            Query myQuery = new Query();
            Criteria myCriteria = null;
            TaxonomyCriteria taxCriteria = new TaxonomyCriteria(strTaxURI);
            PublicationCriteria pubCriteria = new PublicationCriteria(iPublicationID);
            AndCriteria andCriteria = new AndCriteria(taxCriteria, pubCriteria);

            myCriteria = andCriteria;

            myQuery.Criteria = myCriteria;
            string[] componentPresentationURIs = myQuery.ExecuteQuery();

            // Display query results
            ComponentPresentationFactory presentationFactory = new ComponentPresentationFactory(iPublicationID);

            // Create a ComponentPresentation to hold each presentation to be displayed in the loop
            ComponentPresentation cp = null;

            foreach (string componentPresentationURI in componentPresentationURIs)
            {
                // Get the component presentation given the component URI and the component template ID
                cp = presentationFactory.GetComponentPresentation(componentPresentationURI, strComponentTemplateURI);

                if (cp != null)
                {
                    // The Component Presentation may not exist for the given component ID so check if it is null
                    Response.Write(cp.GetContent(true));
                }
            }
        }
    }
}