0

In event code of Tridion 2011 SP1, i need to get the full resolved path of the tcm id which is in the body tag of the component. The component is attached to the page and I am targeting page publish event. Below is the code snippet to get the HTML from the body field of the component. The content of the HTML contains tcmid of the components. I want to resolve those tcm: id to get the physical full path like '/Images/derby_logo_tcm92-12578.jpg'.

ItemFields fielddesc = new ItemFields(compSource.Content, compSource.Schema);

            XhtmlField multiLineBody = (XhtmlField)fielddesc["Body"];
            string strBodyField = string.Empty;                

            if (multiLineBody != null && !string.IsNullOrEmpty(multiLineBody.Value))
            {
                strBodyField = Convert.ToString(multiLineBody.Value);
                builder.AppendFormat("<Description><![CDATA[{0}]]></Description>", strBodyField);
            }           

So my requirement is strBodyField should have the content with all the qualified path resolved. If there are 5 tcm ids in the content of body field, i need the full path instead of the tcm ids.

2

As far as my understanding of architecture is there, this might not be possible out-of-the-box and unless you do some fancy stuff. Just understand, the Event Code is running at the Content Manager Level whereas the Fully qualified path will be generated post successful publishing at the Content Delivery level. You can get the relative path in the event code but not the fully resolved path.

Other experts may share their experience if they have done some fancy stuff :)

  • i meant the relative path like the one which i have mentioned in my query. – Varun Doharey Sep 2 '14 at 14:08
  • For images only or for any TCM URI (of component used on page)? Also, requesting you to update the question accordingly so that people can contribute effectively? – Pankaj Gaur Sep 2 '14 at 14:12
  • Sure,It's for every component used on page. – Varun Sep 3 '14 at 5:44
  • I doubt about this that it is possible to do out-of-the-box – Pankaj Gaur Sep 3 '14 at 9:45
2

Your question is a bit vague, but let me try to clarify what I am basing my answer on:

So my requirement is strBodyField should have the content with all the qualified path resolved. If there are 5 tcm ids in the content of body field, i need the full path instead of the tcm ids.

So I'm assuming that on Save of the Component, You want to update the strBodyField in your Component and get all of its TCM URIs resolved to their full path.

This is not possible to do on save of the Component, resolving a TCM URI of a Multimedia Component can only be done at Publishing time by calling the Engine.AddBinary() method. This is what Publishes the binary (from the Multimedia Component) to the Presentation Server and will generate you a URL.

So now that I have given you an answer (which is certainly not what you were looking for, since it is: no, not possible), let me ask you a question in return to see if we can adjust our answers towards something which is possible.

Why would you actually need to have Component Links resolved in your Component content on save of the Component? (assuming you were talking about a save event)

Please answer this question by editing you main question and adding the additional info in there.

By all means, if I misassumed your question, do update your question too with the relevant details, and then I'll delete my answer and come up with a better one.

  • I need the resolved TCM URI on page publishing event and not on component save event. I got my answer and as per you it is is using Engine.AddBinary() method. I will try out and update if it works. – Varun Sep 3 '14 at 5:48

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.