The code below works for returning all pages for the listed publication, along with the CT's & CP's referenced by those pages. How can I easily get the schemas used by the PT's & CT's also? I don't want to list all schemas, just the ones actually being used.

RepositoryItemsFilterData filter = GetPageFilter();
StringBuilder sb = new StringBuilder();
client = new CoreServiceSession().GetClient;

IdentifiableObjectData[] pages = client.GetList("tcm:0-999-1", filter);

    foreach (IdentifiableObjectData iod in pages)

        PageData pageData = client.Read(iod.Id, new ReadOptions())  as PageData;

        sb.AppendLine("Page: " + pageData.Title);

        foreach (ComponentPresentationData cpd in pageData.ComponentPresentations)
            sb.AppendLine("CP: " + cpd.Component.Title);
            sb.AppendLine("CT: " + cpd.ComponentTemplate.Title);

        //blank line for readability

            return "";

If you're searching for the Content schema, then in your ComponentPresentation loop you can load the component and then read the schema ID or Title from it:

ComponentData c = (ComponentData) client.Read(cpd.Component.IdRef, readOptions);
sb.AppendLine("Schema:" + c.Schema.Title;

If you're searching for Metadata schemas that may be used by the Page or Component Templates, then you can follow the same approach, but loading the Component Template object instead (you already have the Page object outside the loop, so you wouldn't have to load it).

Or use .IdRef instead of .Title if you need the TcmUri.

| improve this answer | |
  • I don't see a Schema property/object in cpd.Component. – Mr Smith Aug 19 '14 at 22:23
  • You're right - too many years using TOM.NET... updating answer... – Nuno Linhares Aug 19 '14 at 22:23
  • Thanks! That worked, though I needed to cast the result of Client.Read to see the Schema property: ComponentData c = (ComponentData)client.Read(cpd.Component.IdRef, new ReadOptions()); – Mr Smith Aug 19 '14 at 22:39
  • 1
    Yeah, otherwise it's an "IdentifiableObjectData". I'll fix that later, glad it worked – Nuno Linhares Aug 19 '14 at 22:54

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.