title: Specifying relative file location in web.config for use by standard C# class library
body: <p>I'm struggling to find a way of specifying a file location in <code>web.config</code> appSettings that avoids using hard-coded paths but allows a non-'web aware' C# library to find a file.</p>
  
  <p>The C# library uses standard <code>File.Open</code>, <code>File.Exists</code> methods, etc. to operate on a data file, which is stored in my web application (ASP.NET MVC) tree, e.g. under:</p>
  
  <pre><code>\content\data\MyDataFile.txt
  </code></pre>
  
  <p>Requirements:</p>
  
  <ul>
  <li>I want to be able to specify my path like, e.g.:</li>
  </ul>
  
  <pre>
          &lt;appSettings>
  this-->     &lt;add key="MyFileLocation" value="~\content\data\MyDataFile.txt" />
  not -->     &lt;add key="MyFileLocation" value="c:\inetpub\wwwroot\foo\content\data\MyDataFile.txt" />
          &lt;/appSettings>
  </pre>
  
  <ul>
  <li>I don't want the C# library to be aware of the web application it's being used in, as it is used in other software, and the web application has no need to know about the configuration of the C# library so I don't really want to pass config info between the layers if possible.</li>
  </ul>
  
  <p>Any suggestions on how I can do this cleanly?  Thanks!</p>