title: How to programmatically populate Sitecore items (Add item and fields)?
body: <p>I'm now battling with adding items via C# to Sitecore database.</p>
  
  <p>The code below executes correctly, however the items aren't being created.</p>
  
  <p>Also, I noticed, that the item["FieldName"]=value; syntax doesn't actually populate the Fields collection.</p>
  
  <p>And Fields collection on the item seems read only, so I can't just call .Add on it (such method doesn't exist).</p>
  
  <p>So - what is the correct way of creating a child item and populating its fields?</p>
  
  <p>I am using the Master database for both the Sitecore backend and this code.</p>
  
  <p>The code I use below:</p>
  
  <pre><code>   using (new Sitecore.SecurityModel.SecurityDisabler())
     {
  
          Database db = Factory.GetDatabase(this.Database);
  
          foreach (var vacancy in Articles.Tables[0].Rows)
          {
              var rootItem = db.GetItem(this.RootItem);
              DataRow dr = (DataRow) vacancy;
  
              var newItem = rootItem.Add(string.Format("{0} {1}", dr["numericID"], dr["job_name"]),
                                         db.GetTemplate(new ID("{GUID}")));
  
              newItem.Editing.BeginEdit();
              newItem["Job Title"] = dr["job_name"].ToString();//
              newItem.Editing.EndEdit();
          } 
  }
  </code></pre>
  
  <p>More info:
  newItem.Template.Fields returns a collection with 100 fields</p>
  
  <p>newItem.Fields returns a FieldCollection with only 9 elements in it.</p>
  
  <p>When I pass through the code newItem["field"].Value = value; it does not increment the newItem.Fields collection count.</p>
  
  <p>Of course the "field" key is consistent with ones present in newItem.Template.Fields[x].Name.</p>