I am working on event code 2011. I want to access a component attached to the page and update a field in that component. The component has two fields (Body and BodyImagePublish), both are text field. I know the code to read the component and acess its field but i don't know why the field shows null even if the component's [Body] field has the value(value is basically a xml)
The code is as below
//Getting the component attached to this page
page2 = (Tridion.ContentManager.CommunicationManagement.Page)publication.GetObject(uRI);
//Getting the component as i want to read the [Body] field. Body has the xml
compToUpdate = page2.ComponentPresentations[0].Component;
//I checked in the log generated by below statement that i am getting the tcm id of the component which has the values
EventHelper.WriteEventToHTMLLog("comtoUpdate string: " + compToUpdate.ToString());
//But the below condition does not satisfy, i opened the component and am sure that there is value in the body field
if (compToUpdate.Content["Body"].Value != null)
{
//this condition does not get satisfied which means that the component is null
}
//I also tried the below code from TOM.NET API chm file, but it throws error
ItemFields contentFields = new ItemFields(compToUpdate.Content, compToUpdate.Schema);
TextField myTextField = (TextField)contentFields["Body"];
string myTextFieldValue = myTextField.Value;
EventHelper.WriteEventToHTMLLog("comtoUpdate body field: " + myTextFieldValue);
Please help me.