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