473,598 Members | 3,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 25992

"olduncleam os" 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" ?>
<configuratio n>
<appSettings>
<add key="Key" value ="Hello World"/>
</appSettings>
</configuration>

class Program
{
static void Main(string[] args)
{
ExeConfiguratio nFileMap map = new ExeConfiguratio nFileMap();
map.ExeConfigFi lename = @"C:\Config.fil e";

Configuration config =
ConfigurationMa nager.OpenMappe dExeConfigurati on(map,
ConfigurationUs erLevel.None);

Console.WriteLi ne(config.AppSe ttings.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...@y ahoo.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.Curre ntDomain.SetDat a("APP_CONFIG_F ILE", "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...@y ahoo.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.comwr ote:
On Aug 14, 4:54*am, olduncleamos <oldunclea...@y ahoo.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.c om/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
2921
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 the name of this is set in machine.config. I was hoping it would be possible to change this in web.config. I got it to work, kind of. Good news is I can change the name in my web.config file. Bad news is that trace.axd still works meaning I can...
2
2386
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 bin\RadControls\v5.3 Under 2.0b2, I had the following setup in my web.config: <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
2
2217
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 itdoesn't affect the Application at all! It still uses the old value. Are the Settings.Setting hardcoded somewhere in the application? I can't find any documentation of this subject, or anyway how I should do
12
2641
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). Inside the function, it's just a dictionary named kwargs (or whaterver, but this is conventional). The truly amazing thing to me is that I am able to write to the Windows registry with so little interface! """Encapuslate a Default Values Object and...
1
6050
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 during the runtime, the user can click on a button and change the connection string without exiting the application. I would really appreciate any sort of help.
0
3762
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 the updated string. I am able to successfully change the string using this code in the Application_Start method of the Global.asax file: Dim csNew As ConnectionStringSettings
0
2897
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 error, but it will not return the contents of any config file I give it. The code to dump the sections always reports sections that do not exist in the file. Looking at appConfig.Type, the public key does not match the one in the file.
4
6473
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 the default configuration in machine.config (which is set on "true"). So i did this in the web.config of the application: <membership defaultProvider="MyMembershipProvider"> <providers>
6
15301
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 values too. I thought this is what ServiceHost is for but is seems way more complicated to use for what I'm trying to do. <system.serviceModel> <bindings>
0
7992
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8400
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8051
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8267
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
3898
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3940
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2414
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1505
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.