I have some Tridion 2011 Core Service code to get a list of all PublishTargets for a given Publication. However, in Tridion 2013 it appears the PublicationTargetData to be null. I am not adding any additional columns to my PublicationTargetsFilterData. But, I feel like if I add the right column I will have the data there. Any idea what column to use?
Here is my working 2011 code:
public static List<PublishTarget> GetPublishTargets(string publicationUri)
{
//var connection = new Connection("http://localhost/Signalr4Tridion/channel");
// Caching
if (pubTargets.ContainsKey(publicationUri))
return pubTargets[publicationUri];
List<PublishTarget> localPublishTargets = new List<PublishTarget>();
string binding = "wsHttp_2013";
//string binding = "netTcp_2013";
using (var client = new SessionAwareCoreServiceClient(binding))
{
client.Impersonate("Dev\\Admin");// (HttpContext.Current.User.Identity.Name);
var readoptions = new ReadOptions();
var filter = new PublicationTargetsFilterData();
var allPublicationTargets = client.GetSystemWideList(filter);
foreach (PublicationTargetData pubTarget in allPublicationTargets)
{
if(!IsValidForPub(pubTarget, publicationUri))
continue;
PublishTarget pubTargetObj = new PublishTarget()
{
Name = pubTarget.Title,
URI = pubTarget.Id
};
localPublishTargets.Add(pubTargetObj);
}
pubTargets[publicationUri] = localPublishTargets;
}
return localPublishTargets;
}
public static bool IsValidForPub(PublicationTargetData pubTarget, string publicationUri)
{
bool hasTarget = false;
foreach (LinkToPublicationData pub in pubTarget.Publications)
{
if (pub.IdRef == publicationUri)
return true;
}
return hasTarget;
}