9

I am retrieving components in a specified folder using Core Services to build an API to expose some content. We have a preview and live environment and I need to retrieve components that have been published to the "live" environment only

code being used for retrieving components:

private static void LoadExistingProducts()
{
    LinkToSchemaData[] schemaLinks = new[] {
        new LinkToSchemaData { 
            IdRef = ConfigurationManager.AppSettings["productSchema"] 
        }
    };

    // Define a filter to return only Components.
    OrganizationalItemItemsFilterData componentFilter = new OrganizationalItemItemsFilterData
    {
        ItemTypes = new[] { ItemType.Component },
        BasedOnSchemas = schemaLinks
    };

    //get xml list of existing product components
    existingProducts = client.GetListXml(
                                    ConfigurationManager.AppSettings["productComponentFolder"],
                                    componentFilter);

    ComponentData component = null;
    XmlSerializer serializer = new XmlSerializer(typeof(Tridion_Product));

    foreach (XElement element in existingProducts.Elements())
    {
        component = (ComponentData)client.Read(element.Attribute("ID").Value, null);
        StringReader readr = new StringReader(component.Content);
        MyReader reader = new MyReader(readr);
        Tridion_Product product = serializer.Deserialize(reader) as Tridion_Product;
        //Place deserialized version of existing object in dictionary for comparison step
        ProductDictionary.Add(product.ProductID, product);
    }
}
6

You can use either IsPublished or GetListPublishInfo methods in order to know if a given component is published to a given target or not.

Try this.

if (channel.IsPublished("[item id]", "[target id]", true)) {

}

or

PublishInfoData publishData = channel.GetListPublishInfo("[item id]")
                                     .Where(w => w.PublicationTarget.Title == "Your Target")
                                     .FirstOrDefault();
if (publishData != null) {

}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.