Isolatedstoragesetting in Windows Forms?

Asked

Viewed 50 times

1

I’m used to using for Windows Phone, so:

using System.IO.IsolatedStorage;
public void putString(string key, string variable)
{
    IsolatedStorageSettings iso = IsolatedStorageSettings.ApplicationSettings;
    if (iso.Contains(key)) //Apenas atualiza os valores das chaves
    {
        iso[key] = variable;
    }
    else //Cria novas chaves
    {
        iso.Add(key, variable);
    }
    iso.Save(); 
}

public void getString(TextBox text, string save)
{
    IsolatedStorageSettings iso = IsolatedStorageSettings.ApplicationSettings;
    if (iso.TryGetValue<string>(text.Name, out save))
        text.Text = save;
}

To write a value and take the value respectively, but in Windows Forms there is no IsolatedStorageSettings What is the easiest method to write data in Windows Forms? It might just be String even, all I found was via file manipulation, which is more complicated.

Is there any method similar to the one I put above? Used to record a kind of dictionary, with key and value, as it would be faster and at lower cost.

1 answer

2


It is on file even. It has the possibility to use the Windows registry but I do not advise.

What you can do to make it easier is to use something ready. I don’t like these ready-made solutions but I know it meets what most need. One of these solutions is to use the ApplicationSettings (has an example using).

Tutorial teaching how to use.

More detailed information.

The class ConfigurationMamager can also be an option. It is less flexible but can solve what you need.

All namespace System.Configuration is dedicated to this.

There are third-party libraries but you should only go after them if they don’t answer.

  • What I found most interesting was using Properties.Settings.Default however I am not getting rs, the IDE does not let the program run with it, tells to check if it is null before saving a value, using thus: Properties.Settings.Default["key"] = "value";

  • "the IDE does not let the program run with it, tells to check" is something very generic. Does it give an error? Give more details. Although maybe that’s a more specific problem.

  • There is no mistake is the only thing that appears

Browser other questions tagged

You are not signed in. Login or sign up in order to post.