How to save to more JSON data to a already created file?

So i followed this tutorial here: and everything works fine but the only thing is that once a file is created that has JSON saved to it i want to be table to add a some more JSON data

right now i am using to Serialize my data and saving it to a file

var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var filename = Path.Combine (documents, "Settings.txt");

File.WriteAllText(filename, "Write this text into a file!");

Just Do not know how to add more data to the already existing data


You want

File.AppendText(filename, "Write this text into a file!"); 

This will append the text to the end of the file. If you need to insert text read the file as a string with File.ReadAllText, manipulate the string and overwrite the original file with the new string.

If you're looking to add update your JSON, you're going to want to load your already existing JSON into an object. Then update your object as required, new entries, updated entries etc.

Once you're ready to save again, clear the text file and re-write your new JSON from the object to the text file.

you can use File.AppendAllText

File.AppendAllText(@"c:\path\file.txt", "text content" + Environment.NewLine);

u can just pass the,

File.AppendAllText(fileName, "text content" + Environment.NewLine);

Need Your Help

MongoDB equivalent of SQL greatest()

sql mongodb mongodb-java

I am in the process of changing the underlaying database from a relational database to MongoDB, and I need to "recreate" the same semantics through MongoDB queries. All in all, this is going fine, ...