"Use Custom URL Path" setting via API?

Quang Lai asked on November 29, 2015 03:14

When creating pages programmatically via the DocumentAPI, how do we make sure the "use custom url path" (checkbox) setting is set to true? This is the check box found in the Pages -> Properties -> URL. Or is giving the DocumentURLPath property a value sufficient - our site appears to be biding by the custom url paths even though the checkbox is not checked in the Pages app, but for the sake of completeness, we'd like to ensure that the checkbox gets checked if possible.

Edit: extra informatoin and code.

We also have the same problem when using a handler to make sure documents gets the right URL Path. Following is a snippet of our handler code:

    private void Document_InsertUpdate(object sender, DocumentEventArgs e) {
        TreeNode node = e.Node as TreeNode;
        string urlPrefix;
        string urlSuffix;
        // ...
        node.DocumentUrlPath = String.Format("/{0}{1}", urlPrefix, urlSuffix);
        node.DocumentUseNamePathForUrlPath = true;
    }

The node.DocumentUrlPath gets set correctly, but the "use custom URL path" checkbox is not checked even with node.DocumentUseNamePathForUrlPath set to true as above. We've cleared cache and refreshed to make sure it isn't a visual display problem.

Correct Answer

Joshua Adams answered on December 1, 2015 17:40

What exactly do you want to accomplish? By using the name path for url path, that means that the document will use the name as the url. By having the use custom url path, that mean that you want it to be something other than the name. If I have a document named A and want the name to remain as A, then I make sure the name is used as the url path, otherwise, if I wanted that same document to be named B, then I would use a custom url path and use B instead. Are there particular documents that you would like to do this for, or all?

0 votesVote for this answer Unmark Correct answer

Recent Answers


Laura Frese answered on November 29, 2015 08:31

try
doc.DocumentUseNamePathForUrlPath = true;

0 votesVote for this answer Mark as a Correct answer

Quang Lai answered on November 30, 2015 15:34

Thanks Laura, I should've mentioned that I did set that property to true, but when viewing on the Pages app, the "Use custom URL path" checkbox remains unchecked.

0 votesVote for this answer Mark as a Correct answer

Laura Frese answered on November 30, 2015 20:50

Do you save the document after that?
doc.Update() or doc.Insert()

Can you include a code snippet?

0 votesVote for this answer Mark as a Correct answer

Quang Lai answered on December 1, 2015 16:40

Hi Laura, yes we do the proper Insert() call. The problem also exists in our handler code (we need to adjust the URL for CMS created pages as well). I've updated my original post with more info and handler code snippet.

0 votesVote for this answer Mark as a Correct answer

Quang Lai answered on December 1, 2015 17:48

Hi Joshua, we want to use a custom URL path for ALL pages, and have the "use custom URL Path" checkbox checked. It sounds like DocumentUseNamePathForUrlPath is way off the mark, and so I'll make sure to set it to false.

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on December 1, 2015 18:58

Are you needing to change the entire url for these pages, or just the ending(document name)?

0 votesVote for this answer Mark as a Correct answer

Quang Lai answered on December 1, 2015 21:04 (last edited on December 1, 2015 21:06)

The entire URL. Thanks.

Edit: wanted to reiterate that the URL saving is fine, it's getting that "use custom URL path" checkbox checked that is at issue. When we view the information in the Page -> Properties -> URL, we see that our code-generated URL path is there, but the check box is not checked.

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on December 2, 2015 15:05

Do you have the global setting checked for using the document name as the path? Go to Settings -> URLs and SEO and check there.

0 votesVote for this answer Mark as a Correct answer

Quang Lai answered on December 2, 2015 21:00

Thanks Joshua, that setting was indeed checked. But per your earlier input, we updated our code to explicitly set DocumentUseNamePathForUrlPath to false, and now the "use custom url path" checkbox is showing up as checked on any new pages (created via the CMS or programmatically).

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on December 2, 2015 22:04

Glad thats working for you!

0 votesVote for this answer Mark as a Correct answer

Steven Bell answered on May 25, 2016 20:25 (last edited on May 25, 2016 20:26)

So, what's the answer? How do you use the API to set the value of the "Use Custom URL Path" checkbox?

And how do you set the path type?

0 votesVote for this answer Mark as a Correct answer

Steven Bell answered on May 25, 2016 21:10

This works:

                document.DocumentUrlPath = "/MyCustomPath/" + document.NodeAlias;
                document.DocumentUseNamePathForUrlPath = false;
                document.Update();

Still not sure how to edit the path type, though.

0 votesVote for this answer Mark as a Correct answer

Quang Lai answered on May 25, 2016 21:20

Hi Steven, yes your code is almost exactly the same as what we used. Essentially make sure there is a DocumentUrlPath value, and that DocumentUseNamePathForUrlPath is set to false.

We didn't have to modify the path type and so I don't know that answer sorry.

0 votesVote for this answer Mark as a Correct answer

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