I need to convert below event code(Tridion 2009) in Tridion 2011. Can anyone please help me ??
Convert component type and get fields and Multimedia property
//Sample Code
Component compCurrent = null;
compCurrent = page.ComponentPresentations[1].Component;
string compTitle = compCurrent.Info.OwningPublication.Title;
string compID = compCurrent.ID;
string compTitleValue = compCurrent.Fields["Title"].value[1];
string fileName = compCurrent.Multimedia.Filename;
Convert component type and page publish
//Sample Code
Tridion.ContentManager.Interop.TDS.Page page2 = null;
page2 = (Tridion.ContentManager.Interop.TDS.Page)TDSEClass.GetObject(uRI, EnumOpenMode.OpenModeView, TDSEClass.GetPublication(TcmUri.PublicationId.ToString()), XMLReadFilter.XMLReadAll);
page2.Publish(targets, false, true, true, DateTime.Now.AddMinutes(-82.0), DateTime.MinValue, DateTime.Now, true, EnumPublishPriority.Normal, false, 0);
My whole method is as below. The parameter named Page in method is of type
Tridion.ContentManager.CommunicationManagement.Page
And the whole method body is written in event code of Tridion 2009.
public void ProcessSciencePrizeGalleryPageForPublish(Page page, TcmUri pubTargUri)
{
Component compCurrent = null;
EventHelper o = null;
TDSEClass class2 = null;
Page page2 = null;
Component component = null;
Component component3 = null;
Component component4 = null;
PublicationTarget targets = null;
StringBuilder builder = new StringBuilder();
XmlDocument document = new XmlDocument();
string prefixUrl = string.Empty;
try
{
o = new EventHelper();
class2 = new TDSEClass();
class2.Impersonate("MTSUser");
targets = class2.GetPublicationTarget(pubTargUri);
string str = "";
compCurrent = page.ComponentPresentations[1].Component;
Publication publication = class2.GetPublication(page.Publication.ID);
string str2 = "<image>";
builder.AppendFormat("<comptcm>{0}</comptcm>", compCurrent.ID);
builder.AppendFormat("<pagetcm>{0}</pagetcm>", page.ID);
builder.AppendFormat("<title>{0}</title>", compCurrent.Fields["Title"].value[1]);
if ((compCurrent.Fields["thumbnail"] != null) && (compCurrent.Fields["thumbnail"].value.Count > 0))
{
component3 = (Component)compCurrent.Fields["thumbnail"].value[1];
string strthumbnailimagepath = publication.MultimediaURL + "/" + this.GetImagePublishPath(component3.Multimedia.Filename, component3.ID);
builder.AppendFormat("<thumbnail>{0}</thumbnail>", strthumbnailimagepath);
}
if ((compCurrent.Fields["previewimage"] != null) && (compCurrent.Fields["previewimage"].value.Count > 0))
{
component4 = (Component)compCurrent.Fields["previewimage"].value[1];
string strpreviewimagepath = publication.MultimediaURL + "/" + this.GetImagePublishPath(component4.Multimedia.Filename, component4.ID);
builder.AppendFormat("<previewimage>{0}</previewimage>", strpreviewimagepath);
builder.AppendFormat("<imagesize>{0}</imagesize>", component4.Multimedia.FileSize);
}
builder.AppendFormat("<category>{0}</category>", compCurrent.Fields["category"].value[1]);
string pubDateFormat = string.Empty;
try
{
pubDateFormat = Convert.ToDateTime(compCurrent.Fields["publish_date"].value[1].ToString()).GetDateTimeFormats('s')[0];
// strXMLBody.AppendFormat("<publish_date>{0}</publish_date>", string.Format("{0:yyyy-MM-dd hh:mm:ss}", Component.Fields["publish_date"].value[1]));
}
catch (Exception)
{
}
builder.AppendFormat("<publish_date>{0}</publish_date>", pubDateFormat);
builder.AppendFormat("<short_description><![CDATA[{0}]]></short_description>", compCurrent.Fields["short_description"].value[1]);
builder.AppendFormat("<displayimageonStagProd>{0}</displayimageonStagProd>", compCurrent.Fields["displayimageonStagProd"].value[1]);
string str3 = "</image>";
string uRI;
uRI = o.Value("SCIENCEPRIZEIMAGEGALLERYPAGE");
page2 = (Page)class2.GetObject(uRI, EnumOpenMode.OpenModeView, class2.GetPublication(page.Publication.ID), XMLReadFilter.XMLReadAll);
component = page2.ComponentPresentations[1].Component;
if (!string.IsNullOrEmpty(component.Fields["Body"].value[1].ToString()))
{
document.LoadXml(component.Fields["Body"].value[1].ToString());
XmlNode oldChild = document.SelectSingleNode("descendant::image[comptcm='" + compCurrent.ID + "']");
if (oldChild != null)
{
oldChild.ParentNode.RemoveChild(oldChild);
}
XmlNode node2 = document.SelectSingleNode("images");
XmlElement newChild = null;
newChild = document.CreateElement("image");
newChild.InnerXml = builder.ToString();
node2.AppendChild(newChild);
str = document.InnerXml.ToString();
oldChild = null;
newChild = null;
}
else
{
str = "<?xml version=\"1.0\" encoding=\"utf-8\"?><images>" + str2 + builder.ToString() + str3 + "</images>";
}
if (component.Info.IsCheckedOut)
{
component.CheckIn(true);
}
component.CheckOut(true);
component.Fields["Body"].value[1] = str;
component.Save(true);
component.CheckIn(true);
page2.Publish(targets, false, true, true, DateTime.Now.AddMinutes(-82.0), DateTime.MinValue, DateTime.Now, true, EnumPublishPriority.Normal, false, 0);
}
catch (Exception exception)
{
EventHelper.WriteEventToHTMLLog("ProcessSciencePrizeGalleryPageForPublish: Error " + exception.Message + Environment.NewLine + "StackTrace: " + exception.StackTrace.ToString());
throw exception;
}
finally
{
Marshal.ReleaseComObject(compCurrent);
o = null;
Marshal.ReleaseComObject(class2);
Marshal.ReleaseComObject(page2);
Marshal.ReleaseComObject(component);
Marshal.ReleaseComObject(component3);
Marshal.ReleaseComObject(targets);
builder = null;
document = null;
}
}
Pls help..