How to create document type using API

Pritam Gupta asked on September 1, 2017 12:35

Hello,

I have to create a document type using API, so i refer the Kentico built in API to create Document Page in CMS but using that i am only create a Page Menu Item. I have to create a page for different document type Please help me for that.

below is my code

Code
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

            // Gets the current site's root "/" page, which will serve as the parent page
            TreeNode parentPage = tree.SelectNodes()
                .Path("/Videos/Archived")
                .OnCurrentSite()
                .Culture("en-us")
                .FirstObject;

            if (parentPage != null)
            {
                // Creates a new page of the "CMS.MenuItem" page type
                TreeNode newPage = TreeNode.New("Custom.Video",tree);

                // Sets the properties of the new page
                //newPage.DocumentName = "Articles";
                //newPage.DocumentCulture = "en-us";

                  newPage.SetValue("title", "Page Through API");

                // Inserts the new page as a child of the parent page
                newPage.Insert(parentPage);

Recent Answers


Brenden Kehren answered on September 1, 2017 14:03

When you debug it are you getting an error?

Does the path /Videos/Archived exist?

Can the "Custom.Video" page type be placed below the "CMS.MenuItem? page type?

Does your custom page type have required fields? If so, did you fill them out?

Speaking of required fields, you need to fill out at least the properties you've commented out for the API to create the rest of the items needed for the page.

1 votesVote for this answer Mark as a Correct answer

Pritam Gupta answered on September 4, 2017 14:21

Hello Brenden,

yes there is required field in my page. now i set that field as well so its working fine.

Thank you very much for your help.

0 votesVote for this answer Mark as a Correct answer

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