I made an event handler for publishing: end to create an XML Sitemap for each language available in the Sitecore instance each time Sitecore completes the publication of the site.
As described in Get the languages selected for publication in a publication: end of event :
[...] actually publication: the final event hits once for each language - and you get the language that is published by making EventArgs [0] .Options.Language.
The problem is publishing: end event just removes the event handler once and only for the first language selected. If I select 3 languages (En-US, Pt-BR, Fr-CA) while publishing my Sitecore instance, for example, publish: end event will instantly hit my event handler and display En-US as the property value EventArgs[0].Options.Language. It did not hit my event handler for two other selected languages (Pt-BR, Fr-CA).
I am using Sitecore.NET 8.0 (rev. 150812) .
Below is my configuration file for the event handler:
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<events>
<event name="publish:end">
<handler type="Project1.EventHandlers.BuildXMLSitemap, Project1.SBL" method="BuildSitemap" />
</event>
<event name="publish:end:remote">
<handler type="Project1.EventHandlers.BuildXMLSitemap, Project1.SBL" method="BuildSitemap" />
</event>
</events>
<sites>
<site name="website">
<patch:attribute name="sitemapXmlFileName">sitemap</patch:attribute>
<patch:attribute name="sitemapXmlIndexFileName">sitemapindex</patch:attribute>
</site>
</sites>
</sitecore>
</configuration>
And below is my code:
namespace Project1.EventHandlers
{
public class BuildXMLSitemap
{
public void BuildSitemap(object sender, EventArgs args)
{
Language language = GetLanguage(args);
}
private Language GetLanguage(EventArgs args)
{
Language language;
if (args is PublishEndRemoteEventArgs)
{
var publishArgs = args as PublishEndRemoteEventArgs;
language = LanguageManager.GetLanguage(publishArgs.LanguageName);
}
else
{
var publisher = Event.ExtractParameter(args, 0) as Publisher;
if (publisher == null) return null;
language = publisher.Options.Language;
}
return language;
}
}
}
And here is my copy of Sitecore with language settings:
Configurable Sitecore Languages
And here is the Sitecore Publish Site dialog showing the available languages:
Post a site dialogue