How to make a string in AppSettings and use it later

2

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?

    
asked by anonymous 27.09.2017 / 15:53

3 answers

1

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>
    
27.09.2017 / 15:59
0

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

    
27.09.2017 / 15:59
0

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();
    
27.09.2017 / 16:25