Question

I'm making my first program in C# which is just going to be a simple note making program. I currently have ten tabs, each with a text box for a title and a description. However the program isn't too useful without having a way to save the content in each text box automatically either before shutdown or after editing the content, and then open them up again the next time the application is loaded, so that a potential user could just carry on with their previous notes etc. the next time they want to use the program. It isn't too good having notes deleted every time you close the app. Also, another option might be saving the state of the whole application as a cache or something, which would be easier than saving twenty text files (two per tab) if its even possible. I havent a clue how to do this anyway, and there is nothing too specific on here or any tutorials that I can find on google. Thanks for the help anyway, I'd just like ideas and examples if you can! Bye!

Was it helpful?

Solution

When researching the subject use the keyword persistence:

In computer science, persistence refers to the characteristic of state that outlives the process that created it.

So persistence has many forms: text files, XML, databases, shoot even memory outside the application fits this definition (its a little silly to store things in memory because a restart would destroy everything).

Assuming this is a winforms application then we are talking about driving the application with events. You can have a submit button which somebody clicks to perform a Save to the "persistence" thing you chose (usually a database).

private void Save(object sender, EventArgs args)
{
   //Gather text info e.g.: var myText1 = myTextBox1.Text;
   //Save to the database or wherever using Stream 
   //or SqlConnection or something else.  See below
}

You could choose to save to the database with a SqlConnection or to a file with StreamWriter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top