API Questions on Kentico API.
Version 5.x > API > Adding Pages and Content with the API View modes: 
User avatar
Member
Member
scott_hancock-urmc.rochester - 7/19/2011 9:22:09 AM
   
Adding Pages and Content with the API
Is there a way to create a new page based on an existing template and then to add text to the editable text web parts on the page? I have looked through the dev and api documentation and I can't find an example of doing this.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 7/20/2011 6:11:24 AM
   
RE:Adding Pages and Content with the API
Hi,

how to create a new document based on some template is described in this thread.

To add a text into editable region you may need to get PageInfo of the new document using following method:

CMS.PortalEngine.PageInfoProvider.GetPageInfo(String, String, String, String, Int32, Boolean, GeneralConnection)

public static PageInfo GetPageInfo(
string siteName,
string aliasPath,
string cultureCode,
string urlPath,
int nodeId,
bool combineWithDefaultCulture,
GeneralConnection conn
)


PageInfo object has EditableWebParts property which is Hashtable, so you can save the content into editable region using following example code:

PageInfo.EditableWebParts[idofwebpart] = content;

Best regards,
Ivana Tomanickova

User avatar
Member
Member
scott_hancock-urmc.rochester - 7/20/2011 10:40:15 AM
   
RE:Adding Pages and Content with the API
The thread you mention, despite it's name, actually describes how to clone an ad-hoc template. It looks like you use the Tree Node class to create a page but I'm not sure.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 7/21/2011 2:37:15 AM
   
RE:Adding Pages and Content with the API
Hi,

yes, you are right. I am sorry for confusion.

To select a template you need to set
DocumentPageTemplateID property of TreeNode class. Creation of a new document using API is described here. For inspiration you could also take a look at:
~/CMSModules/Content/CMSDesk/New/NewPage.aspx.cs

Best regards,
Ivana Tomanickova