How to create a new document using Kentico CMS API

In Kentico CMS all information related to the documents are saved inside the database in many joined tables.

The tables used for storing document records are as follows :

CMS_Tree – This table stores the information about the tree structure of the website document content and contains one record for all culture versions for the document.

CMS_Document – This table contains the records for document and each one represents the one language version of the document.

Coupled table – This table contains fields specified with a document-type
like the ‘News’ document-type the coupled table ‘Content_News’ contains the fields NewsTitle, NewsSummary, NewsText etc which are specific for that document-type with each culture versions as one record.

All the tables described above are encapsulated into a single class CMS.TreeEngine.TreeNode and we can work with
the document values using the TreeNode class properties.

Here i had described how to create a document of specific type using the Kentico API.
Example:

//Include the following namespace at the header position of the page
using CMS.SiteProvider;

//Create the instance for the TreeProvider class
CMS.TreeEngine.TreeProvider provider = new CMS.TreeEngine.TreeProvider(CMS.
CMSHelper.CMSContext.CurrentUser);

//Get the Parent node for the new document
CMS.TreeEngine.TreeNode parent = provider.SelectSingleNode(CMS.CMSHelper.
CMSContext.CurrentSiteName, "/MyNews", "en-us");

//Create a new Tree node at the specified 
CMS.TreeEngine.TreeNode node = new TreeNode("cms.news", provider);
if (parent != null)
{

//Now set the properties for the document if the parent node found
node.NodeName = "MyFirstNews";
node.NodeAlias = "MyFirstNews";
node.SetValue("DocumentCulture", "en-us");
node.SetValue("NewsTitle", "MyFirstNewsTitle");
node.SetValue("NewsSummary", "My First News Summary.");
node.SetValue("NewsText", "My First News Text.");
node.SetValue("NewsReleaseDate", DateTime.Now);

//Now insert the document at the proper place New document
node.Insert(parent.NodeID);

}
150 150 Burnignorance | Where Minds Meet And Sparks Fly!