Vinay Joseph
Vinay Joseph

Reputation: 5655

Iterate through Page Alias in Kentico 8.1

Is there a way to iterate in code C# all the page alias (URLs) of each Kentico Page in the website ?

I am using Kentico 8.1

Upvotes: 0

Views: 208

Answers (1)

rocky
rocky

Reputation: 7696

You have to use DocumentAliasInfoProvider to do that.

// Specify site identifier
var siteId = 3;
// Get all docs
var docs = DocumentHelper.GetDocuments().Where("NodeSiteID", QueryOperator.Equals, siteId).Columns("NodeID");
foreach (var doc in docs)
{
    // Iterate through docs and retrieve aliases for each of them
    var aliases = DocumentAliasInfoProvider.GetDocumentAliases().Where("AliasNodeID", QueryOperator.Equals, doc.NodeID);
    foreach (var alias in aliases)
    {
        lbl.Text += alias.AliasURLPath + "<br />";
    }
}

If you don't want to iterate through documents you can directly select aliases of a site:

var aliases2 = DocumentAliasInfoProvider.GetDocumentAliases().Where("AliasSiteID", QueryOperator.Equals, siteId);
foreach (var alias in aliases2)
{
    lbl.Text += alias.AliasURLPath + "<br />";
}

The site identifier can be retrieved by calling:

// For sites other than current
var siteId = SiteInfoProvider.GetSiteID("codename_of_your_site");
// OR
var siteId = SiteContext.CurrentSiteID;

Please refer to the API Examples. enter image description here

Upvotes: 1

Related Questions