6
Reply

reading files

csharp beginner

csharp beginner

10 years ago
822
I am stuck with a small problem. I need help here .... So, please help me if anybody having a solution for this.
 
I am having a no of csv files and each file is having two rows. Now what i want is, reading each file and writing the elements of each row from the csv files, into two fixed arrays.
 
The code i wrote is:
 
 
FolderBrowserDialog folder = new FolderBrowserDialog();
if (folder.ShowDialog() == DialogResult.OK)
{
 string[] filesGot = Directory.GetFiles(folder.SelectedPath);
         try
         {
          List<string> listA = new List<string>();
                List<string> listB = new List<string>();
                foreach (string fileRead in filesGot)
                {
                  string[] datalines = File.ReadAllLines(fileRead);
                        foreach (string line in datalines)
                        {
                            string[] mycolumns = line.Split(',');
                            listA.Add(mycolumns[0]);
                            listB.Add(mycolumns[1]);
                        }
                }
                string[] firstlistA = listA.ToArray();
                string[] firstlistB = listB.ToArray();
 }

Answers (6)