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 8530337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:14:03+00:00 2026-06-11T09:14:03+00:00

this code works fine but my problem is that i need to read the

  • 0

this code works fine but my problem is that i need to read the files that contains ESSD and if this file contains a name in certain line, add it to my listbox1, and if it doesnt contain the name in that line, dont add it to the listbox1.

Thanks.

private void button1_Click(object sender, EventArgs e)
    {
        DialogResult result = this.openFileDialog1.ShowDialog();
        if (result == DialogResult.OK)
        {
            string[] Nomarchivo = this.openFileDialog1.FileNames;
            string NomDirec = Path.GetDirectoryName(Nomarchivo[0]);
            for (int a = 0; a <= Nomarchivo.Length - 1; a++)
            {
                string NomDirGral = Nomarchivo[a].Remove(Nomarchivo[a].Length - 7, 7);
                string NomGral = NomDirGral.Replace(NomDirec, " ");
                NomGral = NomGral.Remove(0, 2);
                foreach (string f in Directory.GetFiles(NomDirec, NomGral + "*"))
                    this.listBox1.Items.Add(f);
                foreach (string h in Directory.GetFiles(NomDirec, "resume*"))
                    this.listBox1.Items.Add(h);
                foreach (string t in Directory.GetFiles(NomDirec, "ESSD1*"))
                    this.listBox1.Items.Add(t);
            }
            string[] list1 = new string[listBox1.Items.Count];
            for (int b = 0; b <= listBox1.Items.Count - 1; b++)
            {
                list1[b] = listBox1.Items[b].ToString();
            }
            string[] list2 = list1.Distinct().ToArray();
            foreach (string g in list2)
                this.listBox2.Items.Add(g);

            Class1 arr1 = new Class1();
            arr1.array(listBox2);
        }
        else { Close(); }
    }
  • 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-11T09:14:04+00:00Added an answer on June 11, 2026 at 9:14 am

    .NET 4 offers a nice function called File.ReadLines(fileName)

    With this function, your above code can be modified as:

    private void button1_Click(object sender, EventArgs e) 
    { 
        DialogResult result = this.openFileDialog1.ShowDialog(); 
        if (result == DialogResult.OK) 
        { 
            string[] Nomarchivo = this.openFileDialog1.FileNames; 
            string NomDirec = Path.GetDirectoryName(Nomarchivo[0]); 
            for (int a = 0; a <= Nomarchivo.Length - 1; a++) 
            { 
    
                //the name we are looking for.
                List<string> namesWeAreLookingFor = new List<string>();
    
                string NomDirGral = Nomarchivo[a].Remove(Nomarchivo[a].Length - 7, 7); 
                string NomGral = NomDirGral.Replace(NomDirec, " "); 
                NomGral = NomGral.Remove(0, 2); 
                foreach (string f in Directory.GetFiles(NomDirec, NomGral + "*")) 
                    this.listBox1.Items.Add(f); 
                foreach (string h in Directory.GetFiles(NomDirec, "resume*")) 
                {
                    this.listBox1.Items.Add(h); 
    
                    var nameLines = File.ReadLines(NomDirec + @"\" + h);
                    foreach (var item in nameLines)
                    {
                        //do whatever you need to get a name in this file here
                        //...
    
                        //Assuming there is one name per line, add the name to the list
                        namesWeAreLookingFor.Add(item);
                    }
                }
                foreach (string t in Directory.GetFiles(NomDirec, "ESSD1*")) 
                {
                    this.listBox1.Items.Add(t); 
                    //try to access the file so we can read line 6 using new .NET 4 method 
                    var lines = File.ReadLines(NomDirec + @"\" + t);
    
                    //see if we even have 6 lines
                    if (lines.Count() < 6)
                        continue;
    
                    String line6 = lines.ElementAt(5);
    
                    //loop through the names we pulled
                    foreach (var item in namesWeAreLookingFor)
                    {
                        //see if line 6  containes that name.
                        if (line6.Contains(item))
                        {
                            //if it exists, then add it to the list and exit the loop.
                            this.listBox1.Items.Add(t);
                            break;
                        }
                    }
                }
            } 
            string[] list1 = new string[listBox1.Items.Count]; 
            for (int b = 0; b <= listBox1.Items.Count - 1; b++) 
            { 
                list1[b] = listBox1.Items[b].ToString(); 
            } 
            string[] list2 = list1.Distinct().ToArray(); 
            foreach (string g in list2) 
                this.listBox2.Items.Add(g); 
    
            Class1 arr1 = new Class1(); 
            arr1.array(listBox2); 
        } 
        else { Close(); } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple code, using Joda-time. Works fine, but I have a problem.
This code works fine to find an available room within certain date, but it
Please i need help, this code below works fine on my localhost, php5.3+ but
This code works fine, but I'll want to handle exception if any thing goes
This code works fine in C#: Expression.Lambda(LambdaBody); But none of the methods for building
This loop works fine in Main function but when copy this loop code in
This code works fine in Chrome. However, in Firefox, when it hits the GMxhr
this code works fine until I start scrolling: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
The code below is creating a server to communicate with clients.This code works fine
web page : http://sideradesign.com/eco-art/gallery/ This code works fine in all brwosers except IE8 (haven't

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.