Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

.NET app.config in non-project directory - how to access?

Posted on 2007-04-10
4
Medium Priority
?
2,514 Views
Last Modified: 2013-12-17
In a .NET C# project I want to place the app.config file in a different directory from the project directory, and be able to access it (ConfigurationManager methods).  How do I handle this case?

For example my app resides in:

c:\work\helloWorld\helloWorld.csproj

I want to put app.config under:

c:\mycomp_name\environment\apps\helloworld\app.config

How do I have my code recognize the app.config in the non-standard location/directory?
0
Comment
Question by:FredZimmerman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Expert Comment

by:DarrenD
ID: 18883409
I'm not sure if this is possible.

The only thing I can think of is to create your own config file outside of the project and just read it in as a normal xml file and retrieve the values. Then any application can access the file to retrieve the values.

I'm not saying it's not possible.

Darren
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 18886121
You would have to have your app create another appdomain which then hosted your app ...

When creating the AppDomain you can specify the location of the App.Config (AppDomainSetup.ConfigurationFile http://msdn2.microsoft.com/en-us/system.appdomainsetup.configurationfile(VS.80).aspx http://www.c-sharpcorner.com/UploadFile/Ashish1/appdomain02132006085918AM/appdomain.aspx?ArticleID=9a7159d9-cac0-4246-bacd-7de46cb9d610 includes an example.

The reason it is done at the appdomain level like this is because the same file is used to control many appdomain options (like where to probe for dlls).


The other alternative which has already been mentioned above is to go through and create a custom app specific config file which is pretty easy to do using XML serialization.

Cheers,

Greg
0
 

Author Comment

by:FredZimmerman
ID: 18890654
I have question with regard to the ExeFilePath for the <app_name>.exe.config.

If I am pointing to an app.config outside my assembly/project directory, do I
set the directory to the Project/Assembly dir or the config file dir; see
following code:

// ASSEMBLY: c:\work\compname\projects\HelloWorld     - .csproj and .DLL reside here
// CONFIG: c:\compname\environment\HelloWorld\STAGING  - app.config goes here

// ? - What should exeFilePath point to?

            ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
            configFile.ExeConfigFilename = exeFilePath;
            Configuration config =
                ConfigurationManager.OpenMappedExeConfiguration(configFile,
                ConfigurationUserLevel.None);            
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 18891892
its the ConfigurationUserLevel that specifies where the file is ... Check out http://msdn2.microsoft.com/en-us/library/system.configuration.configurationuserlevel.aspx

ConfigurationUserLevel.None specifies that it will be in the same directory as the executable.

This will also only apply to your own settings ... there are other settings (such as the CLR settings in the app.config which will not take effect if you use this method). As such you will have 2 config files.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question