Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

We have autoPage Publish implementation, done with CMS.Extensions.EventSystem. With Auto Publish, we wanted to publish one more page which is SitemapXML page. We have Publication and structure group information, how can I get SiteMapXML page which is present inside structure group where I have only Page Title with me.

share|improve this question

2 Answers 2

You can use code below, this function will return the tcmID of the page whose title is "SiteMapPageTitle" and falls under "tcm:x-y-z" structure group.

  string GetSiteMapPageID(Page subject)
    {

        StructureGroup sg = subject.Session.GetObject("tcm:x-y-z") as StructureGroup; // "tcm:x-y-z" is the id of the structure group

        OrganizationalItemItemsFilter fltr = new OrganizationalItemItemsFilter() { ItemTypes = new[] { ItemType.Page } };
        string res =    sg.GetItems(fltr).Where(i => i.Title == "SiteMapPageTitle").FirstOrDefault().Id;

        return res;
    }

But let me add, publishing sitemap with each page could cause publishing performance issues.

The sitemap page could take some minutes if you have a big site. And it will keep on degrading the performance as you add new pages to your site.

It would be good if you go through the link below before implementing it:

What are the best practices to manage the sitemap for a Tridion website?

share|improve this answer

You can use the code @Saurabh suggests so you can get your SiteMapXML Page based on its name and the Structure Group it resides in. However I think it makes a lot more sense to directly use the TCMURI of the SiteMapXML Page and load it rather than getting it from a list of all Pages.

Then the only issue you then (could) have is where would you store the TCMURI of your SiteMapXML Page. There are of course multiple (good and bad) answers to that, I would suggest to use Publication Metadata, which you can then easily get in your event system from your current item:

Publication publication = (Publication)subject.ContextRepository;
ItemFields metadata = new ItemFields(publication.Metadata, publication.MetadataSchema);

Now you can load the SiteMapXML Page in two ways, the .NET way or more like the TOM API was:

// the .Net way
Page siteMapXmlPage = new Page(new TcmUri(tcmUriFromMetadata), subject.Session);

// the TOM API like way
Page siteMapXmlPage = (Page)subject.Session.GetObject(tcmUriFromMetadata);

For more examples on how to get IDs or URIs from Metadata and how to easily store and use them, you can take a look at my Rapid Editorial Interface Event Handler, that also shows how you can leverage the Item Selector Custom URL extension, so you can easily pick the right URI, without having to type it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.