Save data to files | SoloLearn: Learn to code for FREE!

+2

Save data to files

Hi, can you save the data in the program because when you exit it, information from the label and other elements is not stored? The program is written in C #> Windows form.

1/20/2020 5:38:57 AM

_overseer_

10 Answers

New Answer

+1

_overseer_ Alright, ive made a simple project on vs, you can check it out and it's just a simple way to do what youre trying to achieve. https://drive.google.com/file/d/1jzGNcqr4V8TyB28q0QUX0k_y8S9LdeHh/view?usp=drivesdk Note that i've made this project completely from the web with no personal memory, which proves you can do it too, hope it helps.

+3

Please explain better what you're trying to achieve, do you have a form with some text boxes, and you want that when you reopen this form the text will stay there? If so, do you always want to have the same text there or do you want that when you close the app no matter what was in there it will load next launch?

+2

Well then, that's really simple. There are many ways on when to save the text, either on a button press event, or when the form closes event, you choose. Then, in the code that runs in the event you choose, You can use the library System.IO and it's class File. You can use File.WriteAllText and Read to manage the data. Now, it's up to you if you want to store it inside a text file in a specific structure, or you want to store it with json with a library called Newtonsoft - you pick it. Now, this is all without any research so if I got something wrong or you need help then ask me.

+2

The way your app looks, I guess the plus sign means you can add another element? If so, then I really suggest using json. You should make a class that structures all the data of one element. Then, every time you add a new element, make a reference to it with the class and add it to a list. This way, when you close the app you can use newtonsoft https://www.newtonsoft.com/json/help/html/SerializeWithJsonSerializerToFile.htm and turn the list to json text and save it to a file. Turning an object to json is called serialization and turning text into an object is called deserialization. Hope these keywords will help you search for the info you need. good luck

0

Coder's Crux Yes, I want all texts and numbers saved when I reopen the program)

0

Coder's Crux https://prntscr.com/qq2mom

0

Coder's Crux Thank you, I'll try

0

Coder's Crux For me, this topic is new, could you help to understand the code, I am just new to programming?

0

sure thing, send me your code in dm

0

Coder's Crux No code yet (, because to me this method of saving is new and not clear