3

I have progressed with the event code and I am gaining confidence in it. Now I am stuck with below.

I am able to read the component(if condition is working fine, the logs shows that it enters in the if code) with the following code:

if ((compPresentationCurrent.Component.Content["Thumbnail"] != null) &&
   (compPresentationCurrent.Component.Content["Thumbnail"].Attributes[3].Value != string.Empty))
{
    //The below two lines is throwing error as i do not know how to get the multimedia image
    // attached to this component. 
    // I tried to convert to string and again to object but in vain
    object objComponent = (object)compPresentationCurrent.Component
                          .Content["Thumbnail"].Attributes[3].Value;
    Component tempComp = (Component)objComponent;
}

But I want to read the multimedia component attached to that component, So my component compPresentationCurrent.Component.Content["Thumbnail"] has a image which is multimedia component and I want to read the image path and the image size and for the same. In tridion 2009 event code I did it like below:

//compCurrent is a type of Component, and is the main component which holds
//various multimedia components(i.e. images).
if ((compCurrent.Fields["thumbnail"] != null) &&
   (compCurrent.Fields["thumbnail"].value.Count > 0))
{
    Component component3 = (Component)compCurrent.Fields["thumbnail"].value[1];
    string strthumbnailimagepath  = publication.MultimediaURL + "/" + 
                                    this.GetImagePublishPath(component3.Multimedia.Filename,
                                                             component3.ID);
}

But in new event code it is throwing error.

Can anyone suggest how to do that. Also I am looking for TOm.NET API Documentation, I searched on google and got this link https://stackoverflow.com/questions/10585437/sdl-tridion-tom-net-documentation but no lucks as it is not showing the exact methods and ways to do in event code. Is there any .chm file as it was in TOM API?

1 Answer 1

1

You're reading the fields in a very TOM-ish way... in 2011+ you should use something along these lines:

ItemFields fields = new ItemFields(component.Content, component.Schema);
ComponentLinkField linkField = (ComponentLinkField) fields["thumbnail"];
Component thumbnailComponent = linkField.Value; //(or linkField.Values[0]

Keep in mind too that indexes in c# are 0 based, not 1 based.

The TOM.NET CHMs are available for download from SDL LiveContent (login required).

2
  • In fields["thumbnail"];, Is key name case sensitive ? Because it shows me error like - Error The given key was not present in the dictionary
    – Urvesh
    Mar 7, 2014 at 14:50
  • 4
    Yes xml names are always case sensitive...
    – user219
    Mar 7, 2014 at 15:22

Your Answer

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

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