423,484 Members | 2,471 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,484 IT Pros & Developers. It's quick & easy.

Change default config file name

P: n/a
I am trying to share one config file between multiple console apps. Is
there anyway I can set the config file name for the current
application?

Thanks in advance.
Aug 13 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"olduncleamos" wrote:
I am trying to share one config file between multiple console apps. Is
there anyway I can set the config file name for the current
application?

Thanks in advance.
Hi Amos,

You can't specify configuration name like you can do with the output name of
the assembly, but you can create your own configuration file, name it
whatever you want and load it with . The code below demonstrates how to do
this. Config.file was originally a regular app.config file which was renamed
and copied to another folder.

C:\config.file
---
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Key" value ="Hello World"/>
</appSettings>
</configuration>

class Program
{
static void Main(string[] args)
{
ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = @"C:\Config.file";

Configuration config =
ConfigurationManager.OpenMappedExeConfiguration(ma p,
ConfigurationUserLevel.None);

Console.WriteLine(config.AppSettings.Settings["Key"].Value);
}
}

Using this method you will probably lose all type safety benefits gained
through a Settings file though. There may be ways to tell a Settings file
that the underlying configuration file is not the application configuration
file, but I am not aware of this possibility.
--
Happy Coding!
Morten Wennevik [C# MVP]

Aug 14 '08 #2

P: n/a
On Aug 14, 4:54*am, olduncleamos <oldunclea...@yahoo.comwrote:
I am trying to share one config file between multiple console apps. Is
there anyway I can set the config file name for the current
application?

Thanks in advance.
Hello!!

Use the following line of code to change default config file

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", "c:/test.config");

use the same line of code in both the projects to set a common config
file for both the projects

Hope this helps.
-Cnu
Aug 14 '08 #3

P: n/a
On Aug 14, 4:54*am, olduncleamos <oldunclea...@yahoo.comwrote:
I am trying to share one config file between multiple console apps. Is
there anyway I can set the config file name for the current
application?

Thanks in advance.
Also check out

Using an External Configuration Source section in the article
http://www.odetocode.com/Articles/418.aspx

-Cnu
Aug 14 '08 #4

P: n/a
On Aug 14, 2:06*am, Duggi <DuggiSrinivasa...@gmail.comwrote:
On Aug 14, 4:54*am, olduncleamos <oldunclea...@yahoo.comwrote:
I am trying to share one config file between multiple console apps. Is
there anyway I can set the config file name for the current
application?
Thanks in advance.

Also check out

Using an External Configuration Source section in the articlehttp://www.odetocode.com/Articles/418.aspx

-Cnu
Thank you all. Works beautifully.
Aug 14 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.