title: How to read and update external web.config by a c# Windows forms application
body: <p>I am building a c# Windows application to maintain a WEB application - special to create and update values in a web.config file. I have tried many suggestions here, but all of them are simply describing to read and write config files from inside the application. Part of the web.config:</p>
  
  <pre><code>- 
   &lt;configuration&gt;
      &lt;system.web&gt;
          &lt;customErrors mode="Off"/&gt;
  
          &lt;compilation debug="true" targetFramework="4.0" /&gt;
          &lt;globalization culture="" enableClientBasedCulture="true" uiCulture="" /&gt;
  
          &lt;pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" /&gt;
      &lt;/system.web&gt;
      &lt;appSettings&gt;
          &lt;add key="DocPath" value="~/serverdocs/docs" /&gt;
  
          &lt;add key="TextForLabel1" value="This is some text"/&gt;
  ..
  </code></pre>
  
  <p>I tried to read the file  - special all keys from appSettings -like</p>
  
  <pre><code>    var xmlDoc = new XmlDocument();
          xmlDoc.Load(FName); // name and path from web.config file
  </code></pre>
  
  <p>And then to read all nodes like :</p>
  
  <pre><code>            foreach (XmlNodeList xmlnodes in xmlDoc.SelectNodes("configuration/appSettings"))
              {
                  foreach ( XmlNode node in xmlnodes)
                  {
                  string MyKey = node.Name;
                  string MyVal = node.Value;
                  }
  
              }  
  </code></pre>
  
  <p>But there are always errors like 
  The object of type "System.Xml.XmlDeclaration" cannot be converted to Type "System.Xml.XmlNodeList". Or the items are simply not found depending on how I write the select value.
  I have tried '//configuration'  and 'configuration/appSettings' and others.</p>
  
  <p>Sometimes I am probably blind reading my own code and detecting the error - sorry - any suggestion is welcome.</p>