I have an old method(mentioned below) for GUI extension which works fine in Tridion 2011 and 2013 where I am passing Publication Target and get all child Publications. But now when I deployed that code to WEB 8.5 it's not working. Also, I am getting an error
Exception message: Unable to cast object of type Tridion.ContentManager.CoreService.Client.TargetTypeData to type Tridion.ContentManager.CoreService.Client.PublicationTargetData
It seems like PublicationTargetData
is eliminated and not supported for Web 8.5. Please help me out to get rid of this issue.
public Dictionary<string, string> GetValidChildPublicationList(string PublishingTargetUri)
{
var client = _CoreServiceSession.GetClient();
string publicationUri = GetCurrentPublicationIdFromObj();
_childPublications = new Dictionary<string, string>();
List<string> validPublications = new List<string>();
///Gets the list of Publications exisitng for current Publishing Target
PublicationTargetData target = (PublicationTargetData)client.Read(PublishingTargetUri, new ReadOptions());
foreach (LinkToPublicationData pub in target.Publications)
{
validPublications.Add(pub.IdRef);
}
///Gets the child publications of the current item's publications
UsingItemsFilterData usingPublicationsFilter = new UsingItemsFilterData
{
BaseColumns = ListBaseColumns.IdAndTitle, // to specify the detail in the XML
ItemTypes = new[] { ItemType.Publication }, // to specify certain items
};
IEnumerable<XElement> usingPublicationXMLList = from comp in client.GetListXml(publicationUri, usingPublicationsFilter).Elements()
select comp;
///Add the current publication information to list of valid publications
PublicationData currentPublication = (PublicationData)client.Read(publicationUri, new ReadOptions());
if (validPublications.Contains(currentPublication.Id))
_childPublications.Add(currentPublication.Id, currentPublication.Title);
///If the Publication is present in
foreach (XElement element in usingPublicationXMLList)
{
if (validPublications.Contains(element.Attribute("ID").Value))
_childPublications.Add(element.Attribute("ID").Value, element.Attribute("Title").Value);
}
return _childPublications;
}