Windows form Options for local storage(no DB) - c#

I have a windows form application. I need to store date value it should be available after the application restart. One option is saving in a file which can be accessible and modified.I have tried embedded resource but it is read only.Is there any option for windows form application to persist such variables.

You can use a local file (xml, ini, app.config, etc...) or you can use the Windows Registry if you don't want to write it in a file.

You can use Service based database(local db) just for saving that data.
At first store some default values and then update and retrieve when ever necessary.
It works for me.Not sure it's efficient!

Related

Save user settings for different users in WinForms?

I want to have a save preference option in my WinForms application. The user chooses yes/no and has an option to save preference, upon which the yes/no will be remembered and a form for such a choice will not be popped upon further re running the application.
I read about going to setting and changing but how to do it for different users, since all of them would choose for diff options and I need to maintain that.
Simply using a boolean variable will not help since it will be single user specific. Any suggestions?
(1) At event close main form, you call method/action save result. See How to save data when closing event happen in WinForms?
You can save it to XML file (or text file, SQL lite, SQL Server, etc), popular way is XML file(s).
Read XML file to get saved result before processing business logic in your WinForms application at Load form event or another event type at early stage of application start-up period.
(2) You also save result at previous period in config file https://stackoverflow.com/a/453230/3728901
Properties.Settings.Default["SomeProperty"] = "Some Value";
Properties.Settings.Default.Save(); // Saves settings in application configuration file
So since i didn't want a database , I am creating a file at the client side and saving the preference there.
At run time , I will read from the file and upon that , will decide whether to send form or not .
you can use a Model and store use selected config into it then you should serilaize it and save on database for specific user when reRun the application you can get config and deserialize it to Model and use it

Save system information (mdf or app.config)

I would like your opinion.
I am creating a WinForm application (C#) and I would like to know if there is any problem using a local database to save the application settings instead of app.config. My system constantly retrieves configuration data to continue processes, but there are not many requests or require data with great information, just to validate whether one configuration or another is activated.
I already use mdf file to generate some filters, I was wondering if there is a problem putting the application settings in it.
My mdf file is 8mb in size, practically the standard when it is created, and will not store much information in it.

WPF Properties.Settings saving and multiple users

In my applications there are some setting saved in the Properties.Settings.Default. These settings can be changed by the user(s) and needs to be saved locally on the computer. While I can save these setting, the problem is that it is only saved for the user currently logged in. Once an user changes a setting it has to be for all users of the computer. How can I accomplish this?
User scoped settings are just that, settings that an individual user can change and will only be saved for that user.
The application scoped settings will affect all users but they are not designed to be changed by a user.
You might want to consider a different approach to storing settings that you want users to be able to change but to affect all users of an application e.g. the Windows registry or an external xml file.
Another option is to use user scoped settings but to change the location to a centralised location so that all users use/save the same settings. See Store user settings into application folder for an option on how to do this.
When you open the Settings Designer window in Visual Studio, you have four values that you need to enter for each setting:
You need to set the Scope property to Application to have a setting that is the same for all users. For the full story, read the Using Application Settings and User Settings page on MSDN.
Application settings cannot be changed, only by hand before the application is run so I do not recommend that approach.
In my opinion, propagating the changes may be generally a bad approach. Since this config (user.config) is generally stored in the user's own folder (under Users), it should not be modified by another user (in fact, without administrator acces, another user cannot even access).
I might recommend using other places to store application specific settings: xml or config file near your application, or maybe the registry.
I would use an external Database for that Stuff...
But if you want it quick and simple just save it to a File on the Harddrive (for example C:\Program_Data\\settings.csv) i would use a csv file because it's not much work...

How to retrieve a variable in memory from a WPF application?

I have a WPF application, when the app runs I need to store a variable in a shared memory.
When the app is being closed and successively restart I need to get the variable previously stored. I need a simple solution, I would avoid using a text file saved in some place.
If the machine is restarted I do now need to get that variable.
Any idea what are my option?
You could use your Settings file to save properties between application sessions.
For more information see this and note the Saving User Settings at Run Time section. It technically is "saved" to a file, but in a much dev-friendly manner.
Edit: That is a link for VS2005, oops! Use ConfigurationManager.AppSettings and refer to this post when saving for newer apps.
If you're wanting to avoid writing/reading files, you could use the Registry.

Preserve data between application executions

I have an application with some textboxes. My user fills the textboxes and runs some methods, when they close the application data is lost (normally).
I want to keep the value of a couple of textboxes and some local variables. It's not worth it to use database, and simple .txt files are not clean enough, is there any other simple and brief way of storing little volumes of data between application runs?
I'm not sure but have heard some wisps about resource files, are they good for this case?
Simplest way is binding your textboxes to application settings:
select texbox you want to preserve
go to Properties > Data > (ApplicationSettings)
add application settings binding to Text property
on FormClosed event save application settings
Saving settings:
private void Form_FormClosed(object sender, FormClosedEventArgs e)
{
Settings.Default.Save();
}
Next time when user will start your application, settings will be loaded from user-specific file, and textboxes will be filled with same data as it was before user closed an application last time.
Also in application settings you can store local variables, but you will have to add settings for them manually, and manually read that setting on application start:
open Properties folder under project > Settings.settings
add settings you want to store (e.g. MyCounter)
set MyCounter type, scope, and default value (e.g. int, User, 0)
read setting to your local variable var x = Settings.Default.MyCounter
on form closed save setting Settings.Default.MyCounter = x just before calling Settings.Default.Save()
There are a couple of options, but with most of them, you're going to be putting a file somewhere, whether it's a text file, resources/config or binary.
Using settings is one option: http://www.codeproject.com/Articles/17659/How-To-Use-the-Settings-Class-in-C
You can also take the serialization route: http://msdn.microsoft.com/en-us/library/vstudio/et91as27.aspx
Or you could possibly look into noSQL databases like MongoDB: http://www.mongodb.org/
You have the following options
A local Microsoft Access database which can store small footprint.
Use a Dictionary, Serialize / Deserialize to filesystem.
The Windows registry.
Assuming you're on Windows (as the tags imply), have you considered the registry?

Categories