Previously sorry for my English...
I want to store connection string in app.config
Does my application need app.config file after it have build
I've tried to delete app.config and then ran application from the release folder but no errors appeared, but when from the debug folder i have got one.
So where app.config's keys embed in application?
By default, when you build; the app.config is renamed to <YourAssembly>.exe.config and copied to the output directory.
This is why it works even if you deleted app.config - the old .config is still in the output directory. Try looking in that directory for a .config file.
Related
I am currently having an issue with removing the app.config file from my project.
I wish to have a single .exe file, however, every time I delete the app.config the program will not run.
Does anyone know of a solution to prevent the application from trying to find a app.config file?
Thanks
I am very new to C# and I have read several posts about using configuration files. I have perhaps a very basic question I have been unable to find an answer to. I created a Config folder inside my project to put some path information for input/output files. There also seems to be a Config folder inside the \bin\debug\folder. My App.config file points to Config\appSettings.config. I can't figure out which Config folder is getting used in my project. Is it the Config folder I created or is it the Config folder inside the \bin\debug\ folder? Thanks in advance for any help and I hope I followed all the rules for posting a question.
I think that it's potentially both files.
Whenever you build your application, the compiled .exe, .dll and .config files are copied or written to the \bin\debug folder. The application is then run from the \bin\debug folder. The App.config file in your project directory gets automatically transformed into a file called ProjectName.exe.config which is what the ConfigurationManager class looks for.
If you use configSource in your App.config file to reference another configuration file such as Config\appSettings.config then this will also need to be copied to your \bin\debug folder so that it can be can be accessed when your program is run.
My solution has two exe apps inside. Console application (Console.exe) and wpf application (MyUI.exe). Wpf application is a startup project, and console one is a small installation tool. Both have app.config file which contains db info. I have problem with this config file after I build the solution. In bin folder I have my wpf app and config file with the same name, e.g.:
MyUI.exe and MyUI.exe.config.
But there is no config file for console application. Is there any setting I should set to make it right?
When I set build action to content and copy to output... to Copy always then I have "App.config" file in bin directory, but there is no "Console.exe.config".
There is no such thing as a solution output folder - each project has it's own output folder, in which the App.config will be placed (after it's renamed to [exe_name].config).
I am making one windows application in c# in where i added one file as app.config file.I have written some code in that file as
<appSettings>
<add key ="FlagForArchiving" value="true"/>
</appSettings>
In 'program.cs' file i am reading this value as
ConfigurationSettings.AppSettings["FlagForArchiving"].ToString();
On local machine i can retrieve value from config file but whenever i am building that application and running on any other machine then I cant read the value from config file.I am trying to run my application on windows 7.Please help me.Thanks in advance.
app.config is renamed to <MyProgramName>.exe.config when you build. When your program runs it will look for that <MyProgramName>.exe.config file, not app.config.
You need to deploy the renamed file (<MyProgramName>.exe.config) along with your program.
In your case, you need to copy over OBViewer.exe, OBViewer.exe.config, and any other files that OBViewer.exe depends on (e.g. other .dll assemblies in your debug/release directory).
By the way, this renamed file is often commonly referred to as "app.config", even if it doesn't have the same filename.
and the app.config file exists on the other machine?
Before reading check if it exists
The exception you get says whats incorrect: "FileNotFoundException"
EDIT
here is the correct way!
if (File.Exists(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile))
{
MessageBox.Show(ConfigurationSettings.AppSettings["FlagForArchiving"].ToString());
}
I kept getting errors in my log file that messageconfig file not found. It turned out that my application was expecting it in the bin\debug folder. What causes the application to expect so? It seems that when project is built it should copy the config file in bin\debug folder. Am i missing a certain project setting?
App/web.Config files are expected to be in the same directory as the application/web root.
Other, referenced config files may be in other directories, as specified in the main configuration file.
If you right click on the .config file, then on properties there is a Copy to Ouput Directory entry.
This should be set to either Copy if Newer or Copy always, if this is set to Do not copy, the .config will not by copied to the debug/release folder where it is expected.
Config files are expected to be in the same location as the executing assembly.
Check out this SO question:
.NET 2.0 Application Settings (user.config) file location
You could set the files build action to "Copy always"..
usually you only need the .exe. Try to clean and rebuild your project..
Hope it helps