1

I have a list of Tridion page URL's in an excel sheet, which should be unpublished on Click of a button for which I am developing a custom page.

How do I read the URL from the publication.? For example, the URL looks like:

"https://www.example.com/us/en/abc/cde/index.html"

Path Represents
us/en Country/Language
abc Folder in structure group
cde Subfolder in abc
index.html The page to be unpublished

Now index.html should be unpublished.

2
1

Reference sample Code for Unpublish PageByUrl using CoreService:

using System;
using Tridion.ContentManager.CoreService.Client;
using System.ServiceModel;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

namespace CoreService.PublishPageByPageURL
{
    class Program
    {
        static void Main(string[] args)
        {
            string structureGroupFolderId = "tcm:9-5-4"; //Unpublishing publication SG Root Id
            string[] destinationTargetUris = { "tcm:0-2-65538" }; // TargetId for Unpublish
            string pageUrl = "/index.html"; //PageURL for Unpublish

            ICoreService client = GetClientHttp("localhost", @"vagrant", @"vagrant");

            Console.WriteLine("Connected to CoreService with user " + client.GetCurrentUser().Title);

            OrganizationalItemItemsFilterData filter = new OrganizationalItemItemsFilterData
            {
                ItemTypes = new ItemType[] { ItemType.Page},
                BaseColumns = ListBaseColumns.Id,
                Recursive = true,
            };

            IEnumerable<XNode> pagesListXml = client.GetListXml(structureGroupFolderId, filter).Nodes();
            Console.WriteLine($"Total Pages: {pagesListXml.Count()} ");

            IDictionary<string, string> pagesURLs = new Dictionary<string, string>();

            foreach (XElement element in pagesListXml)
            {
                string pageId = element.Attribute("ID").Value;

                PageData page = client.Read(pageId, new ReadOptions()) as PageData;
                string pageURL = ((PublishLocationInfo)page.LocationInfo).PublishLocationUrl;

                pagesURLs.Add(pageURL, pageId);

                Console.WriteLine($"pageId: {pageId}, pageURL:{pageURL}");
            }

            if (pagesURLs.TryGetValue(pageUrl, out string pageUri))
            {
                Console.WriteLine($"PageId: {pageUri}");

                // UnPublish the page
                var unpublishInstruction = new UnPublishInstructionData
                {
                    ResolveInstruction = new ResolveInstructionData()
                };
                PublishTransactionData[] unpublishTransactions = client.UnPublish(new[] { pageUri}, unpublishInstruction,
                                                                                destinationTargetUris, PublishPriority.Normal,
                                                                                new ReadOptions());
                Console.WriteLine("UnPublished page; transaction id: " + unpublishTransactions[0].Id);
            }

            Console.Read();
        }

        private static ICoreService GetClientHttp(string hostname, string username, string password)
        {
            var basicHttpBinding = new BasicHttpBinding
            {
                MaxBufferSize = 10485760, // 4MB
                MaxBufferPoolSize = 10485760,
                MaxReceivedMessageSize = 10485760,
                ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
                {
                    MaxStringContentLength = 10485760, // 4MB
                    MaxArrayLength = 10485760,
                },
                Security = new BasicHttpSecurity
                {
                    Mode = BasicHttpSecurityMode.TransportCredentialOnly,
                    Transport = new HttpTransportSecurity
                    {
                        ClientCredentialType = HttpClientCredentialType.Windows
                    }
                }
            };

            hostname = string.Format("{0}{1}{2}", hostname.StartsWith("http") ? "" : "http://", hostname, hostname.EndsWith("/") ? "" : "/");
            var endpoint = new EndpointAddress(hostname + "webservices/CoreService201701.svc/basicHttp");
            var factory = new ChannelFactory<ICoreService>(basicHttpBinding, endpoint);
            factory.Credentials.Windows.ClientCredential = new NetworkCredential(username, password);
            return factory.CreateChannel();
        }
    }
}

I hope it helps

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.