How can I make a string in AppSettings, and then use it, for example, the string in AppSettings is this:
string example="example"
And get the value that is in the AppSettings string and put it in a textbox, how can I do this?
How can I make a string in AppSettings, and then use it, for example, the string in AppSettings is this:
string example="example"
And get the value that is in the AppSettings string and put it in a textbox, how can I do this?
Only use ConfigurationManager.AppSettings[chave]
.
using System.Configuration;
// outras coisas
public static void AlgumaFuncao()
{
var valor = ConfigurationManager.AppSettings[exemplo];
meuTextBox.Text = valor.ToString();
}
Remembering that the application config needs to look like this
<configuration>
<appSettings>
<add key="exemplo" value="Alguma string de exemplo"/>
</appSettings>
</configuration>
In your app.config
:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="exemplo" value="exemplo"/>
</appSettings>
</configuration>
No C # code:
string exemplo = System.Configuration.ConfigurationManager.AppSettings["exemplo"];
Remember to add a reference to System.Configuration
To put in a txtbox you should do this:
txtbox.text = Properties.Settings.Default.teste;
To save it looks like this:
Properties.Settings.Default.teste = txtbox.Text;
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();