Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8112921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:39:52+00:00 2026-06-06T02:39:52+00:00

I want to create an item to sitecore using code behind. I found this

  • 0

I want to create an item to sitecore using code behind.

I found this piece of code and it works perfectly fine.

public void CreateItem(String itmName)
{
    //Again we need to handle security
    //In this example we just disable it
    using (new SecurityDisabler())
    {
        //First get the parent item from the master database
        Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
        Item parentItem = masterDb.Items["/sitecore/content/SOHO/Settings/Metadata/Project"];


        //Now we need to get the template from which the item is created
        TemplateItem template = masterDb.GetTemplate("SOHO/Misc/Project");
        //Now we can add the new item as a child to the parent
        parentItem.Add(itmName, template);


        //We can now manipulate the fields and publish as in the previous example
    }
}

But I want to fill in the fields also. like..

Item.Fields["test"].Value="testing";

For that I found out how to edit an item

public void AlterItem()
{
  //Use a security disabler to allow changes
  using (new Sitecore.SecurityModel.SecurityDisabler())
  {
    //You want to alter the item in the master database, so get the item from there
    Database db = Sitecore.Configuration.Factory.GetDatabase("master");
    Item item = db.Items["/sitecore/content/home"];


    //Begin editing
    item.Editing.BeginEdit();
    try
    {
      //perform the editing
      item.Fields["Title"].Value = "This value will be stored";
    }
    finally
    {
      //Close the editing state
      item.Editing.EndEdit();
    }
  }
}

But I have no idea how to combine those 2 things.

I think of 2 methods.

Method 1

Grab the ID of the Item that I created.

I can grab the Name but Name might be duplicated.

Method 2

Fill in the fields before creating the Item

But then.. again I have no idea how to do those 2 methods.

I would be appreciated if I can get some tips.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:39:53+00:00Added an answer on June 6, 2026 at 2:39 am

    Method item.Add() returns the created item so your code should look like this:

        Item newItem = parent.Add(itemName, template);
        newItem.Editing.BeginEdit();
        newItem.Fields["fieldName"].Value = "fieldValue";
        newItem.Editing.EndEdit();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a link like this using an action link: <%= Html.ActionLink(item.forename
I want to do something like this create type Item as object ( id
I want to create a new work item in TFS using the SDK, and
I want to create something like this |Button| item 1 item 2 item 3
I want to create a Visual Studio Item Template that generates an Item (for
I want to create PayPal button with dynamic price (depending from the item) and
I am new to creating work item types in TFS and want to create
When a new item is created using Tastypie, I want to be able to
I want to create and append an item in jquery, while saving a reference
I want create a cache so that when an item doesn't exist, only one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.