473,915 Members | 4,412 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 26109

"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
2945
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
2400
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
2228
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
2667
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
6081
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
3780
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
2912
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
6491
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
15322
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
10039
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
9881
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7256
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5943
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
6148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4778
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
2
4344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3368
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.