Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinForms - which is easiest approach for persisting some data?

Just building my first WinForms application.

Question - What's the easiest/best approach for saving some data between use of the application (e.g. list of URL with status & date/time in this case)? I don't see any need for a database.

For example * Is just storing to text file easiest? * Or is storing to XML file just as easy in DotNet * How about Windows Registry - is this something generally to avoid? Is it's use compatible across all versions including Windows 7 * Database - probably overkill here * A widely used library perhaps?

Thanks

like image 753
Greg Avatar asked Sep 19 '09 03:09

Greg


People also ask

What is WinForms good for?

Windows Forms (WinForms) is a UI framework for building Windows desktop applications. It is a . NET wrapper over Windows user interface libraries, such as User32 and GDI+. It also offers controls and other functionality that is unique to Windows Forms.

What is the replacement for WinForms?

WPF, would be your answer to Windows Forms if you are on the . NET platform.

What is difference between WinForms and Windows Forms?

Winforms and Windows Forms are the same thing. Winforms is the shortened name for Windows Forms.

Is WinForms obsolete?

WinForms won't be deprecated until Win32 is ... which could be quite sometime! WPF on the other hand has few direct dependencies on Win32 so could potentially form the basis of a "fresh start" UI layer on a future version of windows.


1 Answers

Take a look at the Settings of your project (right-click project in Solution Explorer > Properties > Settings tab), you can define a number of variables that are persisted throughout uses of the program for each user, like username, last update time, proxy server, anything like that. The settings themselves are serialized to XML and live in the Application Settings folder for each user, but you can specify default or application-specific settings as well.

You can then use the settings like this:

MyNamespace.Properties.Settings.Default.MySetting

More info about settings files can be found @ MSDN or the Code Project

This is great if you only need to store a few variables between sessions. If you need to store a larger amount of data, look into either one of the database options suggested in the other answers, or serialization.

like image 92
Dale Avatar answered Nov 15 '22 04:11

Dale