Since there is no default configuration file In a WP8 app, what is the best way to store the configuration values, e.g. WCF service URL, User Name and Password. I want these values to be available and updatable when phone restarts and app is closed.
Thanks in advance.
You should use IsolatedStorageSettings.ApplicationSettings
.
Save a value:
IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
appSettings.Add("email", "[email protected]");
appSettings.Save();
Load a value:
IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;
string val = (string)appSettings["email"];
See the MSDN tutorial here: How to: Store and Retrieve Application Settings Using Isolated Storage. It is a desktop Silverlight tutorial but it works the same way in Windows Phone.
EDIT:
Using IsolatedStorageSettings.ApplicationSettings
can be problematic if your app uses background agents (thanks @RichardSzalay for the info).
If your agent only reads, IsolatedStorageSettings.ApplicationSettings
with a Mutex is recommended.
Source: Background agent best practices for Windows Phone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With