I am new in .net.
I am actually converting a Console application into Windows application in .net. And I want to include some configuration files in the windows application.
I know that for web application there is Web.config and for Console application there is App.config to have the configuration details.
But I don't have any ideas about the configuration file in windows application. I have to include the configuration details in my windows application that included in the console application that i want to convert.
UPDATE
Problem Fixed.
It is a fault from my part. I also copied startup tag. Can anyone please tell me for what this tag.??
Thant you all for the replay.
A windows application is a WinForms or WPF application and use the same App.Config renamed in yourappname.exe.config as in Console Applications. So just go on with that
An excellent series of articles on configuration files (I will dare to say the reference)
Unraveling the Mysteries of .NET 2.0 Configuration
Go to the project's properties and change to the "Settings" tab. You might see a message that no settings file is present right now. If you click the link, one will be created.
Add one setting as a dummy so that all sections in the app.config file are created (<applicationSettings> or <userSettings> and the respective section for your namespace). Then, open the original config file in a text edit, copy the settings lines (not the lines containing the <namespace.properties.settings> start and end tags) and then paste them into the new app.config. Make sure that you copy application settings to the <applicationSettings> section and user settings to the <userSettings> sections accordingly.
The next time you open the Settings tag, you'll be asked whether you'd like to import the new settings.
There’s a really simple way to do this.. simply go to the File \ Add New Item menu, or hit Ctrl+Shift+A
You’ll notice that it’s already set to App.config for you. Just hit the Open button.
If you look in the Solution Explorer, you will see that the config file is in your project:
Now build your application, and take a look in the \bin\debug\ folder. You’ll see that the configuration file has automatically been generated and named correctly for your executable:
Reference taken from HERE
Right click on your project go to -->Add --> New Item and then you will find a dialog as shown
Related
Issue:
Applies to: .Net core 3.1 WPF Gui application
in a .net core application, I cannot find the configuration file.
It must have been created somewhere since the application can load and store settings correctly.
Anyone an idea where the file might have been saved?
Steps to reproduce
Create .net core wpf gui app
Create a Settings File:
Write stuff to configuration:
config.Default.LastUpdate = DateTime.Now;
config.Default.Save();
config.Default.Reload();
Relaunch the application and make sure that stuff is loaded correctly from the configuration:
According to the Microsoft Documentation and to Experience from previous .Net 4.5 Apps, a config.xml file should be created in the application's directory. But there is nothing to be found:
Also a Search in the whole project directory yields no result:
The settings files are now saved under the following path:
C:\Users\[username]\AppData\Local\[Your_App_Name]\[Your_App_Name]_Url_yhk4xacfqpnpuvqwry4zvrqsrky5rxpk\[Version]
I guess you are looking for a file in a wrong directory. I've followed steps and created *.settings file. It's located in same folder along with *.csproj file.
You've mentioned config.xml file. Guess, now it's a part of a *.settings file. Try to open a *.settings file with some code editor like VS Code and you will see an xml inside of it. I guess that's what you're looking for.
I can't get the Application Configuration File template to show up under my Add > New Item > Visual C#. I've run a repair. I've uninstalled and reinstalled. I've deleted and added Cache folders. I've run devenv.exe /InstallVSTemplates. Nothing is working.
If anyone can tell me specifically what installation elements I should be including, and specifically what type of Project I need to start that might help.
I want to create a simple .Net Web Form in .Net and C# and need to include an app.config file.
When you create a new project (depending on the type of project like a web application for example) it will automatically create a template app.config file.
Worst case just make a txt file in notepad and call it [Appname].config
Another way would be to go in the project properties, then the Settings tab. If there are no settings yet, a link should exist in the middle of the empty tab to create a default setting file. Add one Application or User setting and save. Among other things a config file will be created for you too.
I am building a C# application. it has some parameters saved of a file named "settings.ini" .
Of course, I managed my application to read settings ,offer an interface for editing them and finally save them back to the ini file.
Would you please tell me how to include this setting file to the installation package (VS2008)
Thanks.
Instead of using an ini file, you should be using a .config file - that's the normal configuration option for .NET application with quite a lot of built in support.
You should be able to add an app.config file to your project from the new item screen in Visual Studio.
Take a look at Configuration Files on MSDN for more detail and the AppSettings class (this page includes some examples).
I want to save some settings on a config file for future use.
I'm trying to use the regular code that I see on all the tutorials -
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["username"].Value = m_strUserName;
// I also tried -
//config.AppSettings.Settings.Remove("username");
//config.AppSettings.Settings.Add("username", m_strUserName);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
Now - I can see that on runtime - the file "...vshost.exe.config" on "Debug" folder is changes, nut when I close my application - all the changes are deleted.
What can I do?
To test using the normal exe's config file un-check the box for "Enable the Visual Studio Hosting Process" in the "Debug" tab in the project properties menu. That will make visual studio no-longer use the vshost.exe file to launch and the correct config file will be used.
When you deploy your application to your end users, there is no vshost.config.
Your changes will be applied to the real exe.config. So you don't have to worry for this.
When you build your application in a debug session, the app.config file, present in your project, gets copied over to the output directory. Then this config file gets copied to vshost.config as well. In this way the contents of app.config overwrites any changes made during a debug session in the vshost.exe.config.
However let me say that writing this kind of information into an application config is a bad practice. The configuration file should be used only to store permanent configuration that usually don't change during the lifetime of your application. Connection settings, for example, are valid info to store there because you normally don't change these and you don't want to hard code them.
Settings like the user name should use user.config instead. This config is per-user/per-app and allows read/write access.
I have a problem: change setting in user control's configuration file has no effect.
I can add "setting" to a user control project and can make following code work:
label1.Text = Properties.Settings.Default.DisplayName;
The output of this usercontrol project is "usercontorl1.dll" and "usercontrol1.dll.config".
When I test it in other project, I found that change the value in config file has no effect to its display. And even if there is no config file, it works fine!
How can I solve this problem , I really need a configurable user control.
Thank you.
Windows 7 64 bits
VS 2008
.Net 3.5
Ref:
http://social.msdn.microsoft.com/Forums/da-DK/msbuild/thread/cbbd893c-8d5d-4699-bf51-bdd110946c94
https://stackoverflow.com/questions/6505252/winform-store-configuration-data-for-user-control
Writing/Reading User-Defined settings in app.config file
You need to copy the config section to the App.Config of the using project.
The (only) file used at runtime is AppName.exe.config
When I test it in other project, I found that change the value in
config file has no effect to its display. And even if there is no
config file, it works fine!
Add the configuration of the user control in the "other project" i.e. the driving project.
ConfigurationManager class visualizes things in the current AppDomain and since your user control loads in the driving application's App Domain, the ConfigurationManager code would refer to the App.Config of the current AppDomain.
I believe that should help!
regds,