title: C# docx bookmarks loop
body: <p>I want to iterate through all bookmarks inside document and set text to each bookmark.Name from datagridview cells values which is already loaded. I'm stuck here in this loop. Please, any suggestions?</p>
  
  <pre><code>using (Novacode.DocX document = DocX.Load(template))
  {
      foreach (Novacode.Bookmark bookmark in document.Bookmarks)
      {
          //MessageBox.Show("\tFound bookmarks {0}", bookmark.Name);
          //var bookmarks = bookmark.Name;
  
          //document.Bookmarks[bookmark.Name].SetText(dataGridViewRow.Cells[0].Value.ToString());
  
          int i = document.Bookmarks.Count;
  
          var bookmarks = document.Bookmarks[i].Name;
  
          document.Bookmarks[bookmark.Name].SetText(dataGridViewRow.Cells[0].Value.ToString());
          document.Bookmarks[0].SetText(dataGridViewRow.Cells[1].Value.ToString());
          document.Bookmarks[1].SetText(dataGridViewRow.Cells[2].Value.ToString());
          document.Bookmarks[2].SetText(dataGridViewRow.Cells[3].Value.ToString());
          document.Bookmarks[3].SetText(dataGridViewRow.Cells[4].Value.ToString());
  
          //document.Bookmarks[bookmark.Name].SetText(dataGridViewRow.Cells[2].Value.ToString());
          //document.Bookmarks[bookmark.Name].SetText(dataGridViewRow.Cells[3].Value.ToString());
          //document.Bookmarks[bookmark.Name].SetText(dataGridViewRow.Cells[4].Value.ToString());
          //document.Bookmarks[bookmark.Name].SetText(dataGridViewRow.Cells[5].Value.ToString());
          //document.Bookmarks[bookmark.Name].SetText(dataGridViewRow.Cells[6].Value.ToString());
          //document.Bookmarks[bookmark.Name].SetText(dataGridViewRow.Cells[7].Value.ToString());
          //document.Bookmarks[bookmark.Name].SetText(dataGridViewRow.Cells[8].Value.ToString());
          //document.Bookmarks[bookmark.Name].SetText(dataGridViewRow.Cells[9].Value.ToString());
          //document.Bookmarks[bookmark.Name].SetText(dataGridViewRow.Cells[10].Value.ToString());
          //document.Bookmarks[bookmark.Name].SetText(dataGridViewRow.Cells[11].Value.ToString());
      }                   
      document.SaveAs(path2);
  }
  </code></pre>