Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

I am writing a C# TBB for CT. i need to check all images in a folder and publish them. Do we have any method to check published path of a particular binary. I don't want to republish the binaries untill its not changed.

    if (Component.Schema.Title.Equals("Album"))
        {
                                string k = Component.OrganizationalItem.Id;
                                OrganizationalItem folder = engine.GetObject(k) as OrganizationalItem;
                                IList<Component> list = folder.Components(true);
                                foreach (Component comp in list)
                                {
                                    if (comp.Schema.Title.Equals("multimedia image schema") )
                                    {
                                        Filter f = new Filter();
                                        //f.Conditions["ItemType"] = ItemType.Component;
                                        f.Conditions["ItemType"] = ItemType.MultimediaType;
                                        xml.WriteStartElement("image");
                                        xml.WriteAttributeString("id", comp.Id);

                                       // need to check if binaries are published and what its published path
                                        xml.WriteAttributeString("src", PublishBinary(comp));
 xml.WriteEndElement();//image

                                    }
                                }

        } 

I am publishing an xml containing all information of those multimedia types like alt text, src, date, country etc.

share|improve this question

1 Answer 1

You can get the location that binaries are published to by default from Publication.MultimediaUrl. You will need to do a bit more work to detect if binaries have been updated since the last time they were published however.

  • You will need to check different targets depending on whether you are publishing to staging or live, so will need to have some configuration somewhere to give you the base site domain based on the publication + publication target/target type.
  • The modified date of the binary on the webserver is very unlikely to be the same as the modification date of the binary component in the CMS (the deployer server(s) could be in different timezone(s), the binary could have been updated after the XML is rendered, but before it is deployed and so on...)
  • Your PublishBinary method may publish the binaries to different locations than the default

A better approach might be to check the last time your XML page was published to the corresponding target (you can see this in the Content Explorer, by selecting Where used on the page and going to the Published To tab, so it must be possible using the API) and using this date as the basis for your comparison.

I assume that you still want to put the image path in your XML even if you don't publish it, so in this case you will have to build the path manually, rather than using PublishBinary.

share|improve this answer
    
How can we check if it is published or not for a multimedia component? –  Manoj Mar 17 at 14:08
    
You can't - and I am not suggesting you do that - My recommended approach is to check the last published time for the XML file, and compare that to the revision date of the binary in the CMS –  Will Price Mar 17 at 14:22
    
its a good idea but in this case i will not be able to find first time publishing . Please note that path is not same for all publications. –  Manoj Mar 18 at 10:51
    
First time publishing, you would want to publish all the binaries anyway wouldn't you? If you read the path from Publication.MultimediaUrl in the context publication where you are publishing the page, then it doesnt matter if its not the same for all publications –  Will Price Mar 18 at 10:52
    
No i don't want to publish all the images that's why I need to know its publishing status. –  Manoj Mar 18 at 11:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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