Programatically updating resource files in windows phone 7 - c#

I am using Resource file(.Resx format) to store configuration settings for a WP7 application. I want to edit(and optionally create) resource files programatically in code. I googled around, and found that some of the classes are not available in WP7 SDK, which are present as a part of usual .Net framework.
So, my question is that, is there a way to edit the resx files in code?
I am only storing strings (key, value pair) as settings in resource files. So, is there something else I can do to store these values.
Reference:: System.Resources namespace in:
1) .Net framework 4 - http://msdn.microsoft.com/en-us/library/system.resources.aspx
2) WP7 SDK - http://msdn.microsoft.com/en-us/library/system.resources(v=VS.95).aspx
WP7 Newbie Here!!, Help is much appreciated.
Update:
My Use case for the above scenario.
1) It's a read frequently, update once in a while configuration settings.
2) I need to access about 300+ such settings, and want to do as much minimum (directly invoking I/O functions) as possible.

You can store them in IsolatedStorageSettings which is very well managed in WP7 applications.
IsolatedStorageSettings.ApplicationSettings["Key"] = object;
Just one point, beware that IsolatedStorageSettings is persisted to phone when your application is tombestoned or exitted. In case of unexpected exit it will not persist on the phone. Although you can always enforce persisting it using the following code:
IsolatedStorageSettings.ApplicationSettings.Save();

Related

Windows 10 Universal App - Best way to store static application settings

I would like to store some configurable data (hosts, keys etc.) in my universal app. The data would be defined before running the app and never changed at runtime. What is the best way to achieve this? I've come across a similar question, but there must be some built-in mechanism.
Here you will find some info: Store and retrieve settings and other app data
If you want to have a file with settings that are known at compile time you can add a json or xml file in your solution and use it as a config file in code.

Persisting Application Settings [duplicate]

This question already has answers here:
What is the best way to store user settings for a .NET application?
(8 answers)
How can I save application settings in a Windows Forms application?
(14 answers)
Closed 9 years ago.
The question is quite simple: I have developed a WinForms application using C# .Net 4.0. I want to implement a form where a user can set the settings of the application, like short keys, connection string, server name, financial year etc.
Once user has set all the settings, these settings would be available even after user closes the application and then open it again. Like in many video players, we use hot keys and set keys according to our needs. Every time we run our media player, the settings are preserved, unless we change them again. This is what I want in my application.
Well, one approach hit in my mind. That is to use caching. Actually, I dont want to store this information in my database. It would be an extra overhead. So guys what is the best approach to achieve the criteria I described? If caching, then why? What are the advantages and disadvantages?
Any help is appreciated.
You have many options.
You can use App.Config
You can create a flat text file where all the settings could be
stored. (Use delimiters to separate key and value.)
You can use an XML file to save all the setting.
Most of the program used to store the settings in %AppData% folder.
There is a built in feature for what you are looking to do - the Settings file.
See Using Settings in C# on MSDN:
The .NET Framework 2.0 allows you to create and access values that are persisted between application execution sessions. These values are called settings. Settings can represent user preferences, or valuable information the application needs to use. For example, you might create a series of settings that store user preferences for the color scheme of an application. Or you might store the connection string that specifies a database that your application uses. Settings allow you to both persist information that is critical to the application outside of the code, and to create profiles that store the preferences of individual users.
Though written for .NET 2.0 and Visual Studio 2005, it is still relevant.
Why are a few bits and bytes of settings "overhead"? Also what do you think caching is going to solve? Caching is runtime, so when the user closes the application the settings are lost.
You can store the settings in any way you like. Database, application settings, or roll your own format.

Opening file outside IsolatedStorage

I would like to know if there is a way to open files which are not located in an IsolatedStorage on a WP7 device ? Internals are not really well documented so...
As a developer using the official Windows Phone 7 developer framework, there is no way to access files that are stored outside of isolated storage. In the Mango framework there is an additional AppData location, but this is also sandboxed and is used for deploying SQL CE data to.
You can get images from either the media library or the camera using their respective Choosers: PhotoChooserTask (http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.photochoosertask(v=vs.92).aspx) and CameraCaptureTask (http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.cameracapturetask(v=VS.92).aspx).
These are the only files that are accessible that are not in your app's IsolatedStorage.
In Windows Phone 7.1 / Mango, system data (like Contacts) is shared using the PhoneDataSharingContext. However, there is no indication that third party developers will be able to expose there data using this class and certainly no documentation for it yet.
My guess that it is somehow registered in the application manifest. However, unless it's supported your application won't get approved, even if you do find out how to do it yourself.
with xna, you can access (read-only) the application folder using TitleStorage.OpenStream()

Where to store user preferences for a C# Windows app

Can anyone provide a best-practices example for where to store user preferences for a C# Windows app?
So far I've heard a number of options:
Some people are saying to store it in
SQLite. Is SQLite bundled with .NET
2.0 and immediately available for use to me?
Others have said to use the built-in
Application Settings... but I've
heard that the per-user settings here
disappear if you upgrade the app (an
obvious problem).
I've also considered just storing it
in a .xml file somewhere on disk...
but where it the "correct" place to
store that .xml file for the user?
SQLite is not included with .NET2, but you could ship it with your application
The built-in settings system works fine for simple apps - you do need to add a couple of lines of boilerplate to deal with version changes but it's not complicated.
You could put your xml file here:
Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData)
There is a lot of 'it depends' about your question, as you don't say how much of what types of data you need to store, nor if you have any other reasons to care where it goes.
The per-user settings "disappearing" can be solved thus: .NET ApplicationSettingsBase Should I call Upgrade() every time I load?
Storing user application settings in isolated storage seems to be a best practice.
http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage(v=vs.80).aspx
Storing settings as an xml file is perfectly fine.

C# Application Configuration Data

Hey, I want to store application configuration data. Currently, I'm using INIs but they are too old and now I want to try something new. I'm on .NET platform using C#.
What solutions do I have? app.configs?
The scenario here is like that, I want to let other programs read the configuration data.
Yes, the various .config files (app.config, web.config, etc..) have replaced INI and, to a certain extent, the Registry as the preferred means of storing configuration data for your application.
Any program, .Net or otherwise, can read those files. .Net has the ConfigurationManager class and other languages can simply do XML parsing to get the values they need.
The standard approach with .NET is to use app.config files for application settings and user.config files for user specific settings (the location varies between XP and Vista though).
There's nothing to stop other programs reading the configuration data, you just need to have a configuration setting in the second (or third) application that tells it where to look.
The app.config would be the preferred way of doing things in .NET. Should work fine to read from other applications as well, as long as you give them the right path to the file. And it's just an XML file, so you can read it from non .NET apps as well.
If you're using Visual Studio, you can use Application Settings for this purpose. Just open the automatically added Settings.settings or create another one. They will be automatically available in Properties.Settings.Default and are stored as XML. You can also have multiple settings files for different purposes.
This is a Visual Studio concept rather than a .NET concept.
I often use an SQL table to hold my application settings. I create a singleton class, ususally called AppSettings, that I load with data from the table. The AppSettings class is then used to get the config values instead of directly accessing the config files. For ASP.Net apps, I instantiate the AppSettings class in the Application_Start event in Global.asax.cs.
Doing this gives me a way to allow the user to control some of the app settings, e.g. an email address for notifications. It also can simplify things when maintaining prod, QA, and dev versions of the app (assuming you have separate database instances for each)

Categories

Resources