473,385 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 25923

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: who be dat? | last post by:
Hello all. I'm writing an application that is writing trace information that can be viewed in trace.axd. I would like to rename this and use a different name specific to my application. I know...
2
by: Joel D Kraft | last post by:
I'm using controls in my ASP.NET application from a couple of vendors. Between the vendors and thier versioning, I've set up subfolders under my bin directory: bin bin\Infragistics\v5.2...
2
by: Pieter | last post by:
Hi, I'm using the Settings.settings of VB.NET to define a Connectionstring (Scope = application). When I deploy the Solution, and change this Setting in the app.config-file, it seems that...
12
bartonc
by: bartonc | last post by:
For those of you who have never used the *listofargs and **dictofargs syntax, here is a look at the latter. By using **kwargs, a dictionary of any size is sent into the fuction as dict(a=1, b=2)....
1
by: Sankalp | last post by:
Hi, I am using VB 2005. My application has many data bound controls. The connection is stored in the app.config file. I want the application to start with a default connection string and while...
0
by: Alias | last post by:
Hi - I have a site that runs on a development and production server. I'd like to programmatically change the connection string the provider uses in the web.config file and have the provider use...
0
by: j | last post by:
I'm trying to write a section of code so that several applications that all share some configuration options can load those options from a single .config file. This code compiles and executes w/o...
4
by: Dan | last post by:
H, i want to use for one specific application the default membership provider as defined by default in machine.config, except one element: i want to use requiresUniqueEmail="false" instead of...
6
by: Andrew Jocelyn | last post by:
Hi How do I programmatically change (read/write) the values in this app.config file at runtime? Specifically I want to change the client endpoint address but it would be nice to change other...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.