0
public void PublishComponent()
    {
        string domainName = System.Configuration.ConfigurationSettings.AppSettings["domainName"];
        string userName = System.Configuration.ConfigurationSettings.AppSettings["userName"];
        string passowrd = System.Configuration.ConfigurationSettings.AppSettings["passowrd"];
        timestamp = DateTime.Now.ToString("dd:MM:yy h:mm:ss tt").Replace(":", "_").Replace(" ", "");
        string content = string.Empty;
        client = CoreServiceClientFactory.GetClient();
        string[] pageList = System.IO.File.ReadAllLines(Environment.CurrentDirectory + "\\" + "pagepublish.txt");
        string[] componentList = System.IO.File.ReadAllLines(Environment.CurrentDirectory + "\\" + "componentList.txt");
        string[] publishTargets = new string[] { "live", "preview" };
        // string[] publishTargets = new string[] { "tcm:0-1109-1" };
        //string[] publishTargets = { "tcm:0-30-1" };
        int i = 1;
        int breakValue = 0;
        foreach (var tcmid in pageList.Union(componentList))
        {
            string componenttcmid1 = tcmid;
            ComponentData ComponentContent = null;
            //try
            //{
            //    ComponentContent = client.Read(componenttcmid1, new ReadOptions()) as ComponentData;
            //}
            //catch (Exception ex)
            //{
            //    ComponentContent = null;
            //}

            if (tcmid.EndsWith("-64"))
            {
                string componenttcmid = tcmid;
                string[] page = new string[] { tcmid };
                Console.Write("Start- " + componenttcmid + " - " + i + " of " + pageList.Count());
                Console.WriteLine();
                PublishInstructionData publishInstructionData = new PublishInstructionData
                {
                    RenderInstruction = new RenderInstructionData(),
                    ResolveInstruction = new ResolveInstructionData()
                };
                if (breakValue == 10)
                {
                    breakValue = 0;
                    Thread.Sleep(5000);
                }
                try
                {
                    client.Publish(page, publishInstructionData, publishTargets, PublishPriority.Normal, new ReadOptions());
                    Console.WriteLine(componenttcmid + "Published");
                    Log(componenttcmid, "publish");
                    Console.WriteLine();

                }
                catch (Exception ex)
                {
                    Log(componenttcmid + " - " + ex.Message + ex.StackTrace, "publisherror");
                    Log(componenttcmid, "failedpublish");
                    //client.Update(ComponentContent, new ReadOptions());
                    Console.WriteLine("Failed" + componenttcmid);
                }
            }
            else
            { 
                UsingItemsFilterData filter = new UsingItemsFilterData();
                filter.ItemTypes = new[] { ItemType.Page };
                filter.IncludedVersions = VersionCondition.OnlyLatestVersions;
                XElement nodes = client.GetListXml(componenttcmid1, filter);
                // XDocument xdoc = XDocument.Parse(nodes);
               string pageid = nodes.Value.Attribute("ID").Value;//error on getting and attribute ID
            }
            breakValue++;
            i++;
        }
    }

I have checked for where used but dont know to publish that where used page

Your Answer

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

Browse other questions tagged or ask your own question.