I'm trying to check if a binary is already published to the target and if not publish it.

private bool isCompToPublish(Component component)
    bool compToPublish = false;
    PublicationTarget target = new PublicationTarget(PublicationTargetId, component.Session);
    ICollection<PublishInfo> pubInfoCol = PublishEngine.GetPublishInfo(component);

    if (PublishEngine.IsPublished(component, target))
        if (pubInfoCol.Where(a => a.PublicationTarget.Id == PublicationTargetId).Count() > 0)
            PublishInfo pubInfo = pubInfoCol.Where(a => a.PublicationTarget.Id == PublicationTargetId).OrderBy(a => a.PublishedAt).Last();
            compToPublish = pubInfo.PublishedAt < component.RevisionDate;
        compToPublish = true;
    return compToPublish;

But in some occasions it suddenly did republish the component. The check if (PublishEngine.IsPublished(component, target)) returned a false, although the binary is published to the target.

I even changed the check to if (PublishEngine.IsPublished(component)), but still it returns a false.

And when I check the components XML with: component.ToXml(XmlSections.Info).SelectSingleNode("/*/*/*/*[local-name()='IsPublished']").InnerText it returns a true.

The really weird stuff, is that some of the binaries do behave correctly.

All binaries use the same schema.

Update I went and checked the database and there is actually something different in the Item_States table. The binary that goes wrong: Wrong Binary, with extra rows, in state 0

And here the binary that works correctly: enter image description here

  • From your update I see you marking two binaries which have a publish status, but both with different Component Template IDs. Can you elaborate on how many Component Templates are associated to the Multimedia Schema of the binaries in question, and what settings those templates have? Commented Jul 5, 2013 at 13:11
  • well, i think the binary that goes wrong was published by the template 1744, but is unpublished (so state 0). Afterwards the schema is removed from the template and added to a different one (214001) and was republished (so state 1). Commented Jul 5, 2013 at 13:15
  • 1
    Well in that case the information in the DB is correct; with CT 1744 it is unpublished and with CT 214001 it is published. And I gather that the IsPublished element in the Component XML 300588 gives you false (which indeed appears to be incorrect then)? Maybe check with CS if there is a hotfix related to the incorrect item state. Commented Jul 5, 2013 at 13:38

2 Answers 2


Unless the binary has a Component Template associated with it, which is set to publish dynamically, your binary (even if placed directly on a Page) will never get a publish status of itself (same as with normal Components).

Only Pages and Dynamic Component Presentations (the Component and its dynamic Component Template) have a publish status which you can check through the API.

The difference between PublishEngine.IsPublished(component, target) and the Component XML IsPublished element, is that through the PublishEngine you can gather this information specifically for a given Publication Target, while the element in the Component XML just indicates if it ever has been published (so for any Publication Target). But as indicated above, this will only contain a value if the Component is part of a Dynamic Component Presentation.

So looking at your last comments, you say that it is working for some binaries while all the the same Schema. From that the only conclusion I can make is that at some point there has been a dynamic Component Template associated with the Schema of your Multimedia Components, and since that, any binary published would have gotten its publish status set.

  • So if the xml of the component will set it to true it should indeed give a true from PublishEngine? PublishEngine.IsPublished(component) would return it for every target, am i right? Commented Jul 5, 2013 at 13:10
  • yes PublishEngine.IsPublished(component) will probabaly check the ITEM_STATES table, but its outcome should match what you see in the Component XML I believe. Commented Jul 5, 2013 at 13:13

The component XML "published" field only indicates if a component has been published as a DCP. Of it is published, in the CME you'll see a little globe icon next to the component icon within the publication from where it is published.

IsPublished(component, target) is the function to use, just make sure that the component is in the proper context publication. What I mean is, if it's a local item in your Global Content publication it will not be published, but if it's in the context of the web publication you actually publish from it will be published.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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