Paule Paul
Paule Paul

Reputation: 387

Is it possible to edit a text file in a UWP app?

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

Answers (1)

Andrii Krupka
Andrii Krupka

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

Related Questions