|
||
|
API examples for newer versions Please visit the latest API Examples documentation to view API examples for newer versions of Kentico. |
The following example creates an event.
private bool CreateEvent() { TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Get root document TreeNode root = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", null, true);
// Create a new CMS Page (menu item) document TreeNode node = TreeNode.New("CMS.MenuItem", tree);
// Set values node.DocumentName = "MyNewDocument"; node.DocumentCulture = CMSContext.PreferredCultureCode;
// Get page template PageTemplateInfo template = PageTemplateInfoProvider.GetPageTemplateInfo("cms.empty"); if (template != null) { }
// Insert the document DocumentHelper.InsertDocument(node, root.NodeID, tree);
// Create new Event (booking system) document TreeNode eventNode = TreeNode.New("CMS.BookingEvent", tree);
// Set values eventNode.DocumentName = "MyNewEvent"; eventNode.DocumentCulture = CMSContext.PreferredCultureCode; eventNode.SetValue("EventSummary", "My event summary"); eventNode.SetValue("EventDetails", "My event details"); eventNode.SetValue("EventLocation", "My location"); eventNode.SetValue("EventDate", DateTime.Now); eventNode.SetValue("EventCapacity", 100);
// Get page template PageTemplateInfo eventTemplate = PageTemplateInfoProvider.GetPageTemplateInfo("cms.empty"); if (eventTemplate != null) { }
// Insert the Event (booking system) document DocumentHelper.InsertDocument(eventNode, node.NodeID, tree);
return true; } |
The following example gets and updates an event.
private bool GetAndUpdateEvent() { TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Get event document TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/MyNewDocument/MyNewEvent", null, true);
if (node != null) { // Update value node.SetValue("EventDetails", "My event details were updated."); node.SetValue("EventCapacity", 200); DocumentHelper.UpdateDocument(node, tree);
return true; }
return false; } |
The following example deletes an event.
private bool DeleteEvent() { TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
// Get event document TreeNode eventNode = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/MyNewDocument/MyNewEvent", null, true);
// Get events parent document TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/MyNewDocument", null, true);
if (eventNode != null && node != null) { // Delete event document DocumentHelper.DeleteDocument(eventNode, tree, true, true, true);
// Delete document DocumentHelper.DeleteDocument(node, tree, true, true, true);
return true; }
return false; } |