-3

I created a program and there's for example a openfiledialog to open different filepaths. But when I restart the program all the filepaths in the array are gone, so every time I need to reselect these files.

Is there a solution so when I close the program it'll save the chosen files, so when I start up the program afterwards, I still have these files?

I heard a database could do the job there, now I have 0 experience with databases and there are so many different ways to create one...

My thought of this was writing all the values to a .TXT file and rereading it on startup, but this seems like a messy solution.

If you think a database is a perfect solution, these are the requirements of the database: - Local only - Capable of saving +- 50 variables (int's, strings, bools, ...) - easy use (No need to install other databaseprograms when you install the program itself)

All idea's & tutorials are welcome

Nick Peelman
  • 585
  • 1
  • 10
  • 28
  • The registry used to be one common "database" of such information. If you do go the .INI (text file) route then you'll probably want the registry to point out where your install directory is so you can find it. C# also has settings files that do this kind of thing... –  Apr 17 '13 at 17:36

2 Answers2

3

I recommand you read a little bit about serialization before jumping into it to make sure you understand what you are doing.

I would personally use a Xml Document or a Binary Writer since you have only a few things to serialize.

these are the requirements of the database: - Local only - Capable of saving +- 50 variables (int's, strings, bools, ...) - easy use

For databases you have to install the programs.

If you want a local database I recommand MsAccess which is easy to use when you start.

If you want to push it a little more MySQL is another easy to use (for basic tasks such as this) but you would have to read about the query language which is T-SQL

phadaphunk
  • 12,785
  • 15
  • 73
  • 107
  • Thanks PhaDaPhunk, I'm glad you understand me, I'll try to use a XML Document to do the job ! – Nick Peelman Apr 17 '13 at 17:41
  • MsAccess would require that the client installs MsAccess - OP said no installation required – Justin Bicknell Apr 17 '13 at 17:41
  • @JustinBicknell it is explained in the answer. And it's for informationnal purpose. Take the time to read it you'll see it makes sense. – phadaphunk Apr 17 '13 at 17:43
  • Fair enough - i missed the line that says "you have to install the programs" – Justin Bicknell Apr 17 '13 at 17:47
  • 2
    MySQL does not use T-SQL. T-SQL is the procedural form of SQL for Microsoft SQL Server. Additionally, something like SQLite is installation-free and intended to provide local database storage. That said, it sounds like all he needs is the equivalent of a config file. The .NET configuration system (rather than reading/writing a binary or XML file by hand) should be used in order to remain idiomatic. – Adam Robinson Apr 17 '13 at 17:48
  • 1
    Actually I found something much much easier ! IF you go to the solution properties -> settings, you can add all valuables there :o ! – Nick Peelman Apr 17 '13 at 18:20
  • 1
    You are talking about [Application Settings](http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx). They are in **Project** /properties/Settings. – phadaphunk Apr 17 '13 at 18:24
  • Have a little problem with adding the data type of a `List` to the Application settings. If i hover the `List` code it says it's a `System.Collections.Generic.List` but i can't find anything like that in type -> browse -> type value :( – Nick Peelman Apr 17 '13 at 18:47
  • 1
    I really don't recommand using the config file for what you want to do. Xml is easy to use especially with Xpath so you should look into that. However if you really want to know how to include a list look at this question here someone explained how to do it.. http://stackoverflow.com/questions/8688724/how-to-store-a-list-of-objects-in-application-settings Again, You should not use that to save – phadaphunk Apr 17 '13 at 18:52
  • Why should I not use it? For me it looked like a very easy solution because the code is much easier than my first looks on XML. But if you really do not recommend this, I will use XML :) Thanks again for your time mate – Nick Peelman Apr 17 '13 at 19:00
  • I have to disagree with @PhaDaPhunk. .NET config files provide the capability of storing any serializable object, including `List` or `T[]`. While I will grant that the stored format (a serialized object string in XML) is less efficient than if you were to write the XML yourself, it's a more idiomatic approach. – Adam Robinson Apr 17 '13 at 19:08
  • @NickPeelman: To be clear, your discoverty of "Settings" is what I'm referring to. This is what I would recommend for you. – Adam Robinson Apr 17 '13 at 19:09
  • 1
    If you want to store a list of strings, the easiest option is to select the `StringCollection`. – Adam Robinson Apr 17 '13 at 19:11
  • @AdamRobinson, Oh :P Sorry for that, my bad English in combination with unknown meaning of "SQL"-things are making it hard for me to understand :) - I found `System.Collections.specialized.StringCollection`, hope this will do it, thanks :) – Nick Peelman Apr 17 '13 at 19:12
0

You could store data in various formats on the hard drive: JSON, XML, CSV. I would go with JSON as it is very easy to serialize and deserialize to your in memory objects. However, there other pros and cons to this argument. See https://stackoverflow.com/questions/3536893/what-are-the-pros-and-cons-of-xml-and-json for more info.

Community
  • 1
  • 1
Justin Bicknell
  • 4,804
  • 18
  • 26