How to get URLs with languages prefixes (if enabled) using API

Javier Galvis asked on June 23, 2014 08:54

I'm working on a project of 16 websites on a single Kentico 7 installation. all 16 websites are multilingual (English and French), however, not all of them have a exclusive domain for each language. For these websites which have a single domain for both languages, I enabled the language prefix setting (SiteManager -> Settings -> URLs and SEO -> SEO - Cultures -> Use language prefix for URLs).

Now, I'm trying to generate links, programmatically, to different documents using Kentico API, but I couldn't find any method to get the relative path (or absolute) including the language prefix, if enabled.

I wouldn't like to code a validation for the language prefix setting, and splitting culture to paste it in URLs, each time that I have to generate a link (I don't think it was the cleanest way to do it).

Any suggestion?

Thanks in advance.

Recent Answers


Richard Sustek answered on October 6, 2014 08:11

Hi Javier,

Thank you for your message.

You can use the DocumentURLProvider class to help you generate URLs for documents. Here is a simple API example:

    TreeProvider treeProvider = new TreeProvider(CurrentUser);
    int documentID = 4;
    CMS.DocumentEngine.TreeNode document = treeProvider.SelectSingleDocument(4);
    if (document != null)
    {
        string url = URLHelper.GetAbsoluteUrl(DocumentURLProvider.GetUrl(document.NodeAliasPath));
    }

Let me know if you need anything else.

Kind regards,

Richard Sustek

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.