I am writing a core service to publish the entire pages in a structure group. I have written a recursive method to get all pages in a structure group.
I am loading all pages in a list and publishing them.
I am able to get all pages in a list, but unable to publish them.
My entire code is here.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tridion.ContentManager.CoreService.Client;
using System.Xml.Linq;
namespace CoreServiceApp
{
class Program
{
static int countPage = 0;
static List<string> pageArray = new List<string>();
static void Main(string[] args)
{
SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2011");
//get the structure group TCM ID
Console.Write("Enter TCMID of structure Group:");
string structureGroupTcmID = Console.ReadLine();
String targetTcmId = "tcm:0-70-65538";
Program prog = new Program();
//Call the recursive method to get all pages in structure group
prog.PagePublish(structureGroupTcmID, client);
PublishInstructionData pubData = new PublishInstructionData();
//convert the pages to string
string[] pages = pageArray.ToArray();
//publish
try
{
client.Publish(pages, pubData, new[] { targetTcmId }, PublishPriority.Low, new ReadOptions());
}
catch (Exception ex)
{
Console.WriteLine("Publish: Unable to publish Page"+ex.StackTrace, ex);
}
Console.WriteLine("Total No of Pages" + pages.Length);
client.Close();
}
private void PagePublish(string tcmID, SessionAwareCoreServiceClient client)
{
ReadOptions readOptions = new ReadOptions();
OrganizationalItemItemsFilterData filter = new OrganizationalItemItemsFilterData();
var elements = client.GetListXml(tcmID, filter);
foreach (var element in elements.Elements())
{
String pageCheck= element.Attribute("ID").Value;
String specID = pageCheck.Substring(pageCheck.LastIndexOf('-') + 1, 1);
//check for structure group
//If structure group call method again
if (String.Equals(specID, "4"))
{
PagePublish(pageCheck, client);
}
//its page
else
{
pageArray.Add(pageCheck);
}
}
}
}
}
I am getting error while publishing.
The exception is
Publish: Unable to publish Page
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRunt
ime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean on
eway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan tim
eout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCall
Message methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
at Tridion.ContentManager.CoreService.Client.ISessionAwareCoreService.Publish
(String[] ids, PublishInstructionData publishInstruction, String[] targets, Null
able`1 priority, ReadOptions readOptions)
at Tridion.ContentManager.CoreService.Client.SessionAwareCoreServiceClient.Pu
blish(String[] ids, PublishInstructionData publishInstruction, String[] targets,
Nullable`1 priority, ReadOptions readOptions)
at CoreServiceApp.Program.Main(String[] args) in H:\Documents\Visual Studio 2
010\Projects\PagePublish\PagePublish\Program.cs:line 28
Total No of Pages2
And the exception message is
Value cannot be null.
Parameter name: publishInstruction.ResolveInstruction.
Please let me know is there any better way to do this and fix to resolve the exception.