I'm struggling to find a way of specifying a file location in web.config
appSettings that avoids using hard-coded paths but allows a non-'web aware' C# library to find a file.
The C# library uses standard File.Open
, File.Exists
methods, etc. to operate on a data file, which is stored in my web application (ASP.NET MVC) tree, e.g. under:
\content\data\MyDataFile.txt
Requirements:
- I want to be able to specify my path like, e.g.:
<appSettings> this--> <add key="MyFileLocation" value="~\content\data\MyDataFile.txt" /> not --> <add key="MyFileLocation" value="c:\inetpub\wwwroot\foo\content\data\MyDataFile.txt" /> </appSettings>
- 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.
Any suggestions on how I can do this cleanly? Thanks!