Getting the full url of a page

Carson Wong asked on July 22, 2016 18:19

Hi,

So in my custom webpart, I currently added a Page selector (when I create an instance of the webpart on Kentico). In the code, I'm fetching it and it is returning me the Node GUID of the page.

My first question is: how can I retrieve the full url to that page?

My second question is: is this the best way to achieve this (ie, using a Page selector)?

Recent Answers


Ivan Robalino answered on July 22, 2016 20:09 (last edited on July 22, 2016 20:11)

Hi Carson

For the first question i could suggest the following code

    var node = DocumentHelper.GetDocuments()
                .WhereEquals("NodeGUID", docGuid)
                .FirstObject;
    if (node != null)
    {
        string pageurl = URLHelper.ResolveUrl(DocumentURLProvider.GetUrl(node));
    }

For the second question, page selector is a good approach. Maybe kentico guys could share more about that

1 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 22, 2016 20:34

Typically I use a URL selector and allows you to select a page with the URL vs. a GUID which is very hard to use and reuse later. You can configure the URL selector to only show at a specific node or level as well as remove the other options to choose URLs from.

1 votesVote for this answer Mark as a Correct answer

Anton Grekhovodov answered on July 26, 2016 14:27

I prefer using Page selector which returns GUID of selected page, because if the page is changed, the URL can be changed too, and if you use URL in page selector, you will have a wrong value, because it won't be changed, but if you use GUID, it is unchangeable and you can get a correct URL.

0 votesVote for this answer Mark as a Correct answer

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