Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App.config on windows phone 7?

Dear all, I am building an application on windows phone 7. My application needs some configurations such as Web-service Urls, database name, ... These configurations may be changed whenever needed during deployment time ( but I don't want to re-build the application). In WPF application, I often save these configurations at App.config file, but in WP7 application I can't.

If you met this problem before as well as you have any solution for it, please tell me.

Thanks so much.

Binh Nguyen.

like image 763
Nguyen Minh Binh Avatar asked Mar 01 '11 16:03

Nguyen Minh Binh


2 Answers

WP7 doesn't support the same concept of an app.config file like desktop .NET applications.

Instead, if you need to provide basic configuration information for an app, you can often store constants and property getters in the App.xaml.cs file.

You can then get to those properties by casting Application.Current to App from anywhere in your app.

var property = ((App) Application.Current).MyWebServiceUri;

Other options include

  • Storing an XML, JSON, or INI-style data file as type Content, then opening that file and parsing it at runtime
  • Storing a resource file, parsing at runtime.
like image 138
Jeff Wilcox Avatar answered Sep 19 '22 09:09

Jeff Wilcox


I'm not clear from your question but:

If you want settings that you can change at run time (once deployed) then store this information in IsolatedStorage. You can use an IsolatedStorageFile or IsolatedStorageSettings depending on what is most appropriate to your data.
I've done this lots by having default settings in code which I write to an IsolatedStorageFile on first run of the app. These can then be read and updated as necessary.

If you just want change the values at build time, include the settings in a/the resources (.resx) file.

like image 42
Matt Lacey Avatar answered Sep 23 '22 09:09

Matt Lacey