Reputation: 387
I need to delete one row in my text file. I use the Windows.Storage.StorageFile
library to save my data.
Should I delete the file and create it again or there is a way to remove the line from the middle in UWP?
Upvotes: 0
Views: 653
Reputation: 4306
You need to rewrite your file without the deleted line.
Look at "How to delete a line from a text file in C#?" - it's old (2009) and not tagged with UWP, but it covers the concept and applies to UWP as well, and C# in general.
For UWP you can use the code below:
var lines = await FileIO.ReadLinesAsync(file);
lines.RemoveAt(lineIndex);
await FileIO.WriteLinesAsync(file, lines);
Upvotes: 3