title: Accessing web.config from Sharepoint web part
body: <p>I have a VS 2008 web parts project - in this project is a web.config file:
  something like this:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;connectionStrings/&gt;
    &lt;system.web&gt;
      &lt;appSettings&gt;
        &lt;add key="MFOwner" value="Blah" /&gt;
      &lt;/appSettings&gt;
  …….
  </code></pre>
  
  <p>In my web part I am trying to access values in the appSetting section:
  I've tried all of the code below and each returns null:</p>
  
  <pre><code> string Owner = ConfigurationManager.AppSettings.Get("MFOwner");
   string stuff1 = ConfigurationManager.AppSettings["MFOwner"];
   string stuff3 = WebConfigurationManager.AppSettings["MFOwner"];
   string stuff4 = WebConfigurationManager.AppSettings.Get("MFOwner");
   string stuff2 = ConfigurationManager.AppSettings["MFowner".ToString()];
  </code></pre>
  
  <p>I've tried this code I found:</p>
  
  <pre><code>NameValueCollection sAll;
  sAll = ConfigurationManager.AppSettings;
  string a;
  string b;
  foreach (string s in sAll.AllKeys)
     {
       a = s;
       b = sAll.Get(s);
      }
  </code></pre>
  
  <p>and stepped through it in debug mode - that is getting things like :</p>
  
  <p>FeedCacheTimer<br />
  FeedPageURL<br />
  FeedXsl1<br />
  ReportViewerMessages</p>
  
  <p>which is NOT coming from anything in my web.config file....maybe a config file in sharepoint itself?  How do I access a web.config (or any other kind of config file!) local to my web part???</p>
  
  <p>thanks,</p>
  
  <p>Phil J</p>