Create items programmatically based on template in sitecore

How do you insert an item into Sitecore programmatically based on the template?

Sitecore is famous because of it provides a lot of Apis from which you can create, edit, and delete items in the content tree.Creating a new item using the template is very simple using the Sitecore API.

Follow the below steps to Create items programmatically based on template in Sitecore.

1. Use the Security Disabler to disable the security. Not necessary to login into the Sitecore.
2. Get the Master Database using Sitecore.Data.Database.GetDatabase("master")
3. Get the template type using Item.TemplateItem API for which you need to create the item.
4. Get the Item path where you need to insert the new item. This is the parent item path of the new item.
5. Add the new item to the parent item path.
6. Update the Fields of a new item created using the Item.Editing.BeginEdit() and Item.Editing.EndEdit()

Sample Code to Create items programmatically based on template in Sitecore

Check out the article Publish items in Sitecore programmatically using API to know how to publish the items in Sitecore using the code.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.