4

I want to publish my pages from the publication so I want to attach this publication into existing publication target. Here is my current code:

PublicationTargetData pd=(PublicationTargetData)client.read("tcm:0-7-65537",new ReadOptions());     
ArrayOfLinkToPublicationData linkpub=new ArrayOfLinkToPublicationData();        
LinkToPublicationData plinkData=new LinkToPublicationData();        
plinkData.setIdRef("tcm:0-234-1");      
List l=linkpub.getLinkToPublicationData();  
l.add(plinkData);   
pd.setPublications(linkpub);    
client.update(pd,new ReadOptions()); 

This code is successfully attaching the Publication into the Publication Target but it unfortunately it replaces the Publication Target with the new one. But I don't want to remove the previous Publication from the Publication Target. So kindly suggest any solution.

6

You are instantiating a new ArrayOfLinkToPublicationData();, but instead you should take one which is already available on your publication target pd, add desired element and assign it back.

0

Try the below method to achieve the desired result

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);
            }

But this is not working in Web 8.5 when you pass a TargetType instead of PublicationTargetType(this returns null always in Web 8.5). Anyone has a solution for this scenario?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.