StreamWriter in C#!

Hoshmand Noori 1 Reputation point
2020-01-11T17:17:31.08+00:00

**

how to delete or update a line in a text file using streamwriter ?

**

You shouldn't care about the tags below :) ..

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,990 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael C. McKinnon 81 Reputation points
    2020-01-11T17:47:10.093+00:00

    What about using Linq to do something like that

    string item = usertxt2.Text.Trim();
    var lines = File.ReadAllLines(usersPath).Where(line => line.Trim() != item).ToArray();
    File.WriteAllLines(usersPath, lines);
    

    from here: https://www.codeproject.com/Questions/883725/How-to-remove-a-line-from-Text-File-using-Csharp

    0 comments No comments