title: c# How to write to a ini file
body: <p>I would like to know how i should write text to a ini file. The reading of the file is already done. Now i just have to know how to write to the file.</p>
  
  <p>It should look like this when its in the INI file:</p>
  
  <p><code>[H83052_md7]</code><br />
  <code>Description=H83048 processor mode 7</code><br />
  <code>BootFile=kernel_52.md7</code><br />
  <code>Extension=a20</code></p>
  
  <p>If you would like to see how i read from the file ask me for the source code please because i could not figure out how i should do this.</p>
  
  <p>I write it like this:</p>
  
  <pre><code>namespace Flashloader
  </code></pre>
  
  <p><code>{
      class Controllerlist : List&lt;Controller&gt;
      {
          public Controllerlist FromIniFile()
          {
              StringList input = new StringList().FromFile("Controllers.ini");</code></p>
  
  <pre><code>        Controller controller = null;
  
          foreach (var item in input)
          {
              String line = item.Trim();
  
              if (line.StartsWith("[") &amp;&amp; line.EndsWith("]"))
              {
                  String name = line.Substring(1, line.Length - 2);
  
                  controller = new Controller(name);
                  Add(controller);
              }
              else if (controller != null)
              {
                  int index = line.IndexOf('=');
                  if (index &lt; 0)
                      continue;
  
                  String key = line.Substring(0, index).Trim();
                  String value = line.Substring(index + 1).Trim();
  
                  if (Utils.EqualsIgnoreCase(key, "Description"))
                      controller.Description = value;
                  else if (Utils.EqualsIgnoreCase(key, "Bootfile"))
                      controller.Bootfile = value;
                  else if (Utils.EqualsIgnoreCase(key, "Extension"))
                      controller.Extension = value;
              }
          }
          return this;
      }
  
      public Controller FindByName(String name)
      {
          foreach (var item in this)
              if (Utils.EqualsIgnoreCase(item.Name, name))
                  return item;
          return null;
      }
  }
  </code></pre>
  
  <p>}</p>