© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
The Joker

❔ Help with StreamReader txt file

hello everybody! I'm trying to do a reading inside a .txt file, at first I type a name in a textbox when I give the command that name would be searched inside the .txt file and if it found the name it will be deleted, does anyone have any idea how do that?

private void btnDelete_Click(object sender, EventArgs e)
{
    string path = @"ADDONS\Favorites.txt";
    StreamReader fav = new StreamReader(path);

    string[] lines = File.ReadAllLines(fav.ToString());

    foreach (string line in lines)
    {
        if(line.ToString() == textbox1.Text.ToString())
        {
            line.Replace(line, "");
        }
    }
    fav.Close();
}
private void btnDelete_Click(object sender, EventArgs e)
{
    string path = @"ADDONS\Favorites.txt";
    StreamReader fav = new StreamReader(path);

    string[] lines = File.ReadAllLines(fav.ToString());

    foreach (string line in lines)
    {
        if(line.ToString() == textbox1.Text.ToString())
        {
            line.Replace(line, "");
        }
    }
    fav.Close();
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Reading file (.txt)
C#CC# / help
3y ago
❔ Load txt file
C#CC# / help
3y ago
Streamreader. Double use of Streamreader
C#CC# / help
3y ago
Please can somebody help me with this .txt file?
C#CC# / help
14mo ago