1

I'm attempting to write a function in a UserControl to pull data using ComponentPresentationFactory.. Below is my code..

string ret = "RET: -- ";
        int PublicationID = Convert.ToInt32(Configuration.PublicationId);
        ComponentPresentationFactory cpf = new ComponentPresentationFactory(PublicationID);
        cpf = new ComponentPresentationFactory(PublicationID);
        Criteria criteria = new ItemTypeCriteria(16);
        Query query = new Query(criteria);
        string[] results = query.ExecuteQuery();
        foreach (string componentUri in results)
        {
            ComponentPresentation cp = cpf.GetComponentPresentation(componentUri, "tcm:23-13077-32");
            if (cp != null)
            {
                ret +=  "*" + cp.GetContent(true);
            }
        }
        return ret + " --" ;

The TemplateID is the ID of the Component Template that is contains the TBB that is calling the UserControl. I'm attempting to follow the usage guidelines in the SDL Querying for Content pdf manual, but I'm not getting any data.

2
  • 1
    Do you have any results after you execute Query? In results array? If not, probably you have not published any dynamic component presentation to this publication. If you have values in results, then make sure that components were published with specified component template. And this component template must be dynamic. – Stan Kroshchenko Feb 6 '15 at 19:09
  • And just in case, to publish the DCP that @StanKroshchenko mentions, the Component Template needs to be associated to the Schema for that Component. – Alvin Reyes Feb 6 '15 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.