0

I am trying to create a method to publish and finish the workflow activity using core service. am getting the compile error. Below is my code. Can any one correct me? Its an urgent.

public void PublishComponent(string WorkItemId)
    {
        var client = new SessionAwareCoreServiceClient();
        var readoptions = new ReadOptions();            
        ComponentData component = (ComponentData)client.Read(new TcmUri(WorkItemId), readoptions) as ComponentData;
        List<IdentifiableObjectData> ItemToPublish = new List<IdentifiableObjectData>();            
        ItemToPublish.Add(component);
        PublishInstructionData instruction = new PublishInstructionData();
        PublicationTargetData pubtarget = (PublicationTargetData)client.Read(new TcmUri("tcm: 0 - 21 - 65537"), readoptions) as PublicationTargetData;
        List<PublicationTargetData> target = new List<PublicationTargetData>();
        target.Add(pubtarget);            
        client.Publish(ItemToPublish, instruction, target, PublishPriority.Normal, readoptions);


        WorkItemData workitem = new WorkItemData();
        workitem.Id = new TcmUri(WorkItemId);            
        ActivityInstanceData currentactivity = new ActivityInstanceData();
        ActivityFinishData finish = new ActivityFinishData();
        finish.Message="Published";
        client.FinishActivity(currentactivity, finish, readoptions);
}
Jey
  • 2,137
  • 4
  • 22
  • 40
  • "The compile error" doesn't tell us much. Next time, consider stating the exact error (with stacktrace). That would make it possible for people to answer without trying to compile your code (which takes considerably more effort). – Peter Kjaer Jul 09 '12 at 14:05

1 Answers1

5

There were several problems, but the main is that there's no TcmUri class, like in TOM.NET, it's string in CoreService. And the same for Publish method, it takes string arrays as input, not item arrays, like in TOM.NET

        var client = new SessionAwareCoreServiceClient();
        var readoptions = new ReadOptions();
        ComponentData component = (ComponentData)client.Read(WorkItemId, readoptions);
        List<string> ItemToPublish = new List<string>();
        ItemToPublish.Add(component.Id);
        PublishInstructionData instruction = new PublishInstructionData();
        PublicationTargetData pubtarget = (PublicationTargetData)client.Read("tcm:0-21-65537", readoptions);
        List<string> target = new List<string>();
        target.Add(pubtarget.Id);
        client.Publish(ItemToPublish.ToArray(), instruction, target.ToArray(), PublishPriority.Normal, readoptions);


        WorkItemData workitem = new WorkItemData();
        workitem.Id = WorkItemId;
        ActivityInstanceData currentactivity = new ActivityInstanceData();
        ActivityFinishData finish = new ActivityFinishData();
        finish.Message = "Published";
        client.FinishActivity(currentactivity.Id, finish, readoptions);
Andrey Marchuk
  • 13,301
  • 2
  • 36
  • 52
  • 2
    You can add a reference to Tridion.Common.dll from your project. All classes in Tridion.Common are safe to use outside of a Tridion server. This dll will contain the TcmUri class, which you can use. – Nuno Linhares Jul 09 '12 at 14:33
  • Use this to connect to CoreServiceClient if your web.config or app.config uses the WCF config from the Tridion Live Docs. var client = new SessionAwareCoreServiceClient("netTcp_2011"); – robrtc Jan 16 '13 at 15:07
  • Also, the publishInstruction needs to be updated. Following example used from Building Blocks, //set the publish instructions to publish to child publications PublishInstructionData instruction = new PublishInstructionData { ResolveInstruction = new ResolveInstructionData() { IncludeChildPublications = true }, RenderInstruction = new RenderInstructionData() }; – robrtc Jan 16 '13 at 15:08