469,366 Members | 2,407 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

Change default config file name

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
4 24427

"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
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
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
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.

Similar topics

2 posts views Thread by Joel D Kraft | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.