Change setting in user control 's configuration file has no effect - c#

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,

Related

Adding app.config (Application Configuration File) in Visual Studio Professional 2017

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.

Deploying Windows forms application with Config

I am trying to deploy a windows forms application which uses the properties/settings of the project to store config information.
In a form it is retrieved and sometimes changed by saving as below
Properties.Settings.Default["name"] = textBox1.Text;
Properties.Settings.Default.Save();
I only need to deploy to 3 PCS. Is it enough to deploy the .exe file alone?
Or do I also need the exe.config file ?
Thanks
If your App.config1 file contains default configuration information not embedded in your program, such as a connection string, then yes, you will need to bundle it with your executable.
However the code you've posted shows you're using the "Settings" feature, which is a feature of .NET that runs on-top of App.config. If you use the Settings feature, then your app.config file is (usually) actually stored under your current user's AppData directory and not the same directory as the executable, these files are also created as-required, in which case you won't need to ship the app.config file... assuming you have nothing else in the file.

Configuration file in .net windows application

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

C# - app config doesn't change

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.

C# currentcultureinfo is different than defined

I have a problem where my CurrentCulture is is-IS while I dont have that configured not in my web.config, not on my windows xp, and for some reason this is the locale that is taken into my applications...
where can it be?
It could be in the project (.csproj) file. In VS, unload the project and then edit the project file.
There could be a an XML element named this:
<UICulture>en-US</UICulture>
This sets the default culture.
Other places it could be are configuration files, it could be set in code somewhere when the application starts, or it could be set in the host HTML page if this is a web application.

Categories