Click here to Skip to main content
15,305,577 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a note taking app (for learning purposes) using Winforms.

I have a static class which has an object which stores the notes as:
key: value
title: contents

The guides online for this are very confusing and I am looking for how to keep this object (noteDictionary) persistent so if the form is closed and open again I can still reference it. Also happy if someone can point me to much simpler guide they have found online.


What I have tried:

I have tried using the built in Properties.Settings to visual studio, but am not sure how to use it for objects and not just simple variables.
Updated 13-May-22 4:54am
Richard MacCutchan 13-May-22 7:11am
Most applications like this would store the data in a text file. You could use JSON or XML, but a simple heading word followed by the text would probably be easier.

You could use the XMLSerializer class, see, for instance: C# Simple XmlSerializer example[^].
Member 15634817 13-May-22 9:33am
Ye This ended up working, I've Serialized classes for passing around a program but didn't realise you could just save them into a local file :)
For a single note, the Properties.Settings would suffice, and it's pretty easy to do: either use two settings - one for Key and one for Title:
Properties.Settings.Default.NoteKey = Key;
Properties.Settings.Default.NoteTitle = Title;

Key = Properties.Settings.Default.NoteKey
Title = Properties.Settings.Default.NoteTitle;

Or select a character that won't be in a note ('|' for example) and concatenate them:
Properties.Settings.Default.Note = $"{Key}|{Title}";

string[] parts = Properties.Settings.Default.Note.Split('|');
Key = parts[0];
Title = part[1];

Moving on from there, XML and JSON (or even CSV) are okay choices, but once the number of Notes increases they all become pretty unwieldy solutions and you want to start looking at using a database. Which probably sounds scary, but it's pretty easy and gives you a heck of a lot of advantages, particularly if you later want to share notes between users.

Me? I use a DB for most data storage, even if I suspect there won't be a lot of info as I'm often wrong and it turns out there is ... :laugh:
Member 15634817 13-May-22 11:07am
I have no experience with databases as of yet, but thanks for the answer anyway, as I think it is something I could look at as part of my learning
OriginalGriff 13-May-22 12:02pm
It's worth learning: when you get used to it, they are just so flexible compared to text-based data storage.

Good luck with the education! :thumbsup:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900