So I want to create a simple text file with this code. But when I open the created file , the text is not displayed entirely, the only text I got is from tb1.text (id[2]).
Is there anything wrong here?
private async void Save_Reg()
{
var myfile = (tb3.Text+".xml");
var folderUsed = ApplicationData.Current.LocalFolder;
var folderOp = Windows.Storage.CreationCollisionOption.ReplaceExisting;
var createFile = await folderUsed.CreateFileAsync(myfile, folderOp);
var password = tb2.Text;
var recov = tb1.Text;
string[] id = { myfile,password, recov };
await Windows.Storage.FileIO.WriteTextAsync(createFile, id[0]);
await Windows.Storage.FileIO.WriteTextAsync(createFile, id[1]);
await Windows.Storage.FileIO.WriteTextAsync(createFile, id[2]);
}
is there anything wrong here?
Yes. WriteTextAsync replaces the contents of the current file. It's equivalent to the synchronous File.WriteAllText method. If you want to append, you'll need AppendTextAsync.
Alternatively, concatenate the ids so you know the full contents you want to write, and then call WriteTextAsync just once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With