Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:15:37+00:00 2026-06-01T23:15:37+00:00

I need help with a program i’m building at my internship. The idea is

  • 0

I need help with a program i’m building at my internship.
The idea is to check how frequent a user logs in on any PC.
When a user logs in, that information is logged in a text file, like this format.

01-01-2011 16:47:10-002481C218B0-WS3092-Chsbe (XP-D790PRO1)

Now i need to search the text file and (for example) search the text file for all login dates for the user Chsbe.

My code so far:

private void btnZoek_Click(object sender, EventArgs e)
        {
            int counter = 0; string line;  
            // Read the file and display it line by line. 
            System.IO.StreamReader file = new System.IO.StreamReader("c:\\log.txt"); 
            while((line = file.ReadLine()) != null)
            {     if ( line.Contains(txtZoek.Text) )     
            {
                txtResult.Text = line.ToString();                
            }     

            }  
            file.Close(); 
        } 

My question is, How do i return all the strings in the log containing the searchterm to txtResult?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:15:39+00:00Added an answer on June 1, 2026 at 11:15 pm

    You are already doing a good work. The only error is in the writing of the last line read into the textbox overwriting the previous one.
    You need to use a StringBuilder and a using statement around your disposable Stream like this:

    private void btnZoek_Click(object sender, EventArgs e)         
    {             
        int counter = 0; string line;               
        StringBuilder sb = new StringBuilder();
    
        // Read the file and display it line by line.              
        using(System.IO.StreamReader file = new System.IO.StreamReader("c:\\log.txt"))
        {
           while((line = file.ReadLine()) != null)             
           {     
             if ( line.Contains(txtZoek.Text) )                  
             {          
                  // This append the text and a newline into the StringBuilder buffer       
                  sb.AppendLine(line.ToString());
             }                   
          }               
       }
       txtResult.Text = sb.ToString();
    }  
    

    of course, your txtResult should have the property MultiLine set to true, otherwise you will be unable to see the output.
    Keep in mind that using is the better way to handle this kind of situations because it automatically handles also unexpected file exceptions taking care to correctly close your Stream

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help to identify the bug in my program that I have written
I need help here in a multiplication table program. The program asks the user
I need some help with a program that I am writing for my Systems
I need help creating a script or program that can add users to my
I need help getting my java program ready for release. I have a program
i try to program a LdapAuthentication and i need some help. First i need
I need help on regex or preg_match because I am not that experienced yet
I need help finishing this statement. It is frustrating that two of the PHP
I need help to debug this program . // VirtualFN.cpp : Defines the entry
I need some help with my program. I get this error when I run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.