I was using Tridion 2009 and have just upgraded to 2011. We already have a event code (.net framework 3.5)implemented to track some page publish event in the method 'OnPagePublishPost' and it is working fine. I know how to get components and multimedia component attached to that component from page and then publishing that page.
I need to make the change in the event system now, and on the component save 'OnComponentSavePost' method.
Query 1. In 'ComponentSavePost' method, I want to publish the attached multimedia image component in the component.publish that image using publishbinary method.
My code sample is below:
private void BuildXMLFile(Component Component)
{
Component thumbnailcomp = null;
try
{
EventHelper.WriteEventToHTMLLog("BuildXMLFile: Start");
string strMsgLabel = string.Empty;
StringBuilder strXMLBody = null;
strXMLBody.Append("<xml><image>");
strXMLBody.Append("<componentid>" + Component.ID + "</componentid>");
if ((Component.Fields["title"] != null) && (Component.Fields["title"].value.Count > 0))
{
strXMLBody.Append("<title>" + Component.Fields["title"].value[1].ToString() + "</title>");
EventHelper.WriteEventToHTMLLog("Got title value of the image component");
}
if ((Component.Fields["thumbnail"] != null) && (Component.Fields["thumbnail"].value.Count > 0))
{
thumbnailcomp = (Component)Component.Fields["thumbnail"].value[1];
strXMLBody.AppendFormat("<thumbnail>{0}</thumbnail>","Images" + "/" + thumbnailcomp.Multimedia.Filename + "_" + thumbnailcomp.ID);
EventHelper.WriteEventToHTMLLog("Got thumbnail path value of the science prize image component:" + "Images" + "/" + thumbnailcomp.Multimedia.Filename + "_" + thumbnailcomp.ID);
//how to publish this thumbnailcomp mulitmedia item? I tried to find the publish class but there is no direct publish method
//thumbnailcomp.Info. -
}
}
catch (Exception ex)
{
EventLog.WriteEntry("Event_System", ex.ToString(), EventLogEntryType.Warning, 234);
}
finally
{
EventHelper.WriteEventToHTMLLog("BuildXMLFile: Finally");
thumbnailcomp = null;
}
}