roy doron

roy doron

  • NA
  • 33
  • 20.4k

How to write at the next line in the next opening of the csv file?

Oct 28 2012 5:06 AM
Hello!

At first run, my program, writes to a csv file in the first line,
But, when I'm running my program at the second.. third.. time, it runs over the first line..
how can i correct it?

I would like to have a CSV file input of all the entering to my program.

The code is as follows:

private void WriteToCsvFile()
{
  var us = users.ElementAt(0);
  string names = "Number',";
  string userAnswer = (us.userName + ",");
  foreach (string ss in user)
  {
  string str = Path.GetFileName(ss);
  names = names + str + ",";
  }
  foreach (string ans in us.answer)
  {
  userAnswer = userAnswer + ans + ",";
  }

  using (StreamWriter sw = new StreamWriter("EntranceLog.csv"))
  {
  sw.WriteLine(names);
  sw.WriteLine(userAnswer);
 
  }
 
  this.Close();
}


Thanks you!

Answers (1)