0

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?

Sergey
  • 1,608
  • 1
  • 27
  • 40
Paule Paul
  • 387
  • 3
  • 11

1 Answers1

3

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);
Community
  • 1
  • 1
Andrii Krupka
  • 4,276
  • 3
  • 20
  • 41