How to check "Use custom URL path" checkbox in "URL" tab via Kentico API?

Targutai Yesugei asked on October 17, 2017 09:56


I'm trying to set page url path to route: /foo. So, i'm trying to execute the code : treeNode.DocumentUrlPath = "ROUTE:/foo"; with further treenode updating. After this, i see in admin cms that "Path type" radiobutton and "Path or pattern" are correct, but "Use custom URL path" checkbox is off. How to fix this?

I'm using Kentico 10, version 31.

Thanks in advance.

Correct Answer

Matt Nield answered on October 17, 2017 10:44

Hi, Just trying to replicate your issue, I used the following code

var doc = DocumentHelper.GetDocument(nodeId, treeProvider());

if (doc != null)
    doc.DocumentUrlPath = "ROUTE:lovely-route";

This seemd to work and set the checkbox as expected. But only the first time. If I reset the URL in CMS desck and then call it again, I get the results you're experiencing.

I modified my code as follows:

var doc = DocumentHelper.GetDocument(nodeId, new TreeProvider());

if (doc != null)
    doc.DocumentUrlPath = "ROUTE:lovely-route";
    doc.DocumentUseNamePathForUrlPath = false;

This now sets the Use custom URL path checkbox corectly. It seems that combination of DocumentUrlPath and DocumentUseNamePathForUrlPath determine how this checkbox works. Hope the helps you!

2 votesVote for this answer Unmark Correct answer

Recent Answers

David te Kloese answered on October 17, 2017 10:44

You can set this using

treeNode.DocumentUseNamePathForUrlPath = True;

1 votesVote for this answer Mark as a Correct answer

Targutai Yesugei answered on October 17, 2017 12:01 (last edited on October 17, 2017 12:28)

Matt, David, thank you for answers, i used this property, and checkbox was set correctly.

P.S. Matt, could you check if your page is available via url you set, after this code execution?

0 votesVote for this answer Mark as a Correct answer

Matt Nield answered on October 17, 2017 23:14

Hi Targutai,

Glad to help. I've just gone through the steps again and can confirm the the page was avialble via the set route in my browser.

0 votesVote for this answer Mark as a Correct answer

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