I have created a couple of forms which all must work with a csv file. I can register different users and then login in a profile if it exists. I add the information with StreamWriter:
using (StreamWriter writer = new StreamWriter(filePath, true))
{
writer.WriteLine(username + "," + password);
}
Then i read the information with:
using (StreamReader reader = new StreamReader(filePath))
{
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
string[] userData = line.Split(',');
usernames.Add(userData[0]);
passwords.Add(userData[1]);
}
}
And
bool isFound = false;
for (int i = 0; i < usernames.Count; i++)
{
if (usernames[i] == username && passwords[i] == password)
{
isFound = true;
}
}
I want to add other information to the line like picture location,amount of money,amount of garage space,but everything i've tried from the internet writes the data on a new line,not to the existing line. I got a few tips from our lector-to first read the file and then write to it,but it still doesn't work. Whenever i add the data i use
using(StreamWriter writer = new StreamWriter(filePath,true))
{
writer.Write("the username from the register from" + "," + "the password from the register form" + openFileDialog.FileName("the location of the file/What my lector told me to use"));
}
I only need to know how to add that additional data so i can proceed with the rest of my project. Im sorry if this question has already been answered and thank you for your time.