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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:42:02+00:00 2026-05-26T06:42:02+00:00

I have this part of code that takes a file and puts it in

  • 0

I have this part of code that takes a file and puts it in an ArrayList. The file that will be entered will be a CSV (the current CSV that I use has headers at the first line, so I don’t need that line) and the second line has to be put in an ArrayList.

I use ArrayList because the file can be dynamic, so I am not sure what will be the length of the second line. I tested (with a file that has 7 comma-separated values on the second line) this code and it prints that the ArrayList has a length (fileList.Count) = 1.

What is wrong ?

ArrayList fileList2 = new ArrayList();
private void button3_Click(object sender, EventArgs e)
{
    string filename = "";
    DialogResult result = openFileDialog2.ShowDialog();
    if (result == DialogResult.OK)
    {
        filename = openFileDialog2.FileName;
        textBox3.Text = filename;
        string line2;
        System.IO.StreamReader file2 = new System.IO.StreamReader(textBox3.Text);  //reads file from textbox 
        stringforData = file2.ReadLine();      // this reads the first line that I dont need 
        while ((line2 = file2.ReadLine()) != null)     //read the lines 
        {
            // puts elements into array
            fileList2.Add(line2.Split(';'));//split the line and put it in the arraylist
        }
        file2.Close();
        if (true)    // this is for testind what is happening 
        {
            this.textBox2.Clear();
            textBox3.Text = Convert.ToString(fileList2.Count);
        }
    }
}
  • 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-05-26T06:42:02+00:00Added an answer on May 26, 2026 at 6:42 am

    Don’t you want to use fileList2.AddRange() instead of fileList2.Add() ?
    It seems to me that you are adding one item to the fileList now. That item is an array that contains all items you actually wanted to add to the list. If you get that array first and than use the addRange method, It should be fine.

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

Sidebar

Related Questions

I have this part of code in my functions.php: function cc_admin_enqueue_scripts($hook) { $file_dir=get_bloginfo('template_directory'); wp_enqueue_script('media-upload');
I have this code to run a slideshow (this is only part of what
We have this anonymous function in our code, which is part of the jQuery's
So I have a program which runs. This is part of the code: FileName
This part of an app that I am working on, I have the following
I have this code that makes sure your are logged in, and then making
Lets say in a file I have some code in two files part of
I have a file which has text like this: #1#14#ADEADE#CAH0F#0#0..... I need to create
Currently I have an application that takes information from a SQLite database and puts
I have this part in a method, It should return the page and headers

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.