I am making a video Converter in c# on windows Framework. i want to save loaded files that user add & if it Exit the Application i want to store that files and load when it runs application again. How to do this. ?? Give me idea about how to do this.
3 Answers
Using the settings api may help: http://geekswithblogs.net/mbcrump/archive/2010/06/17/configuring-applicationuser-settings-in-wpf-the-easy-way.aspx

- 11,402
- 17
- 27
-
Link-only answers are generally advised against. Please at least provide a summary of what to do. – Thorsten Dittmar Jul 15 '16 at 12:19
You need to use user settings. Open the project properties in Visual Studio and click the "Settings" tab. You can add a new user setting there of type System.Collections.Specialized.StringCollection
by entering a setting name, selecting the type System.Collections.Specialized.StringCollection
from the combo box and then defining it as a user scope setting.
If you forget to make it a user setting and create an application setting instead, it will be read-only and you have no chance of changing it. Only user settings can be changed.
This will look to your code like a normal list of strings. You can add a new value to the like and save it like this:
Properties.Settings.Default.[Setting name you chose].Add("My String");
Properties.Settings.Default.Save();
Of course you can also loop over the entries like:
foreach (string s in Properties.Settings.Default.[Setting name you chose])
....
The advantage is that you don't need to care about where the settings are stored and how. .NET does all that for you.
Background: Creating settings will add them to the app.config
file. This file will be copied into the output directory when you compile as [exename].exe.config
. When the application starts, the framework will read the application settings from there. The user settings will either be read from there or (if you changed and saved them) from a copy that resides somewhere in the user's application data directory.
Do not, I repeat: do not attempt to modify that .exe.config
file directly from your code, but always use the properties that are automatically generated for you as I described above.

- 55,956
- 8
- 91
- 139
-
I generally find that the string collection is more hassle than help, i doesn't implement IEnumerable
which means its not compatible directly with some of the more useful Linq extensions and causes quite a bit of bloat in your settings file. I'd only recommend it when you are storing complex strings that are hard to split, otherwise just use a string – MikeT Jul 15 '16 at 12:36 -
Yes, but for the OP's purpose it is perfect. He needs to store a list of files (I guess: file names?). Probably he has a list of files internally anyway, so re-loading these files is a simple for-loop. I doubt that being able to use LINQ outweighs the pain of splitting up a string that contains all the file names in this case... Also, while LINQ may be a nice tool, we were able to program without it only 5 years ago. You can still write loops, you know? But that's a different discussion :-) As for the bloated settings file: Who cares whether the file is 1K or 2K or even 10K? – Thorsten Dittmar Jul 15 '16 at 12:39
You could create a Settings class which contains a list of the files previously loaded and then on Exit serialize it to disk and on start deserialize it.

- 332
- 4
- 13
-
-
The Problem with the Framework is that sometimes if you update the application the Settings might be lost. But sure you can first try the built in solution – Thomas Hahn Jul 18 '16 at 05:16
-
1@ThomasHahn There is no problem whatsoever with the builtin application settings if you use them as designed. – Thorsten Dittmar Jul 18 '16 at 08:41
-