I am able to add multiple patients to the txt file, however when I attempt to read all the data from the file, it only prints one patient.
Secondly, when I add a patient, how do I move it onto the next line? at the moment the patient gets appended onto the same line at the first patient.
Could someone please help me? Thankyou
Secondly, when I add a patient, how do I move it onto the next line? at the moment the patient gets appended onto the same line at the first patient.
Could someone please help me? Thankyou
C#:
List<User> PInfo = new List<User>();
if (File.Exists("PInfo.txt"))
{
Stream stream = File.Open("PInfo.txt", FileMode.Append);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(stream, patient);
stream.Close();
stream.Position = 0;
Console.Clear();
DisplayMenu();
}
else
{
Stream stream = File.Open("PInfo.txt", FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(stream, patient);
stream.Close();
stream.Position = 0;
Console.Clear();
DisplayMenu();
}
public static void ViewAllRecords()
{
string choice;
object obj = null;
Stream stream = File.Open("PInfo.txt", FileMode.Open);
BinaryFormatter bf = new BinaryFormatter();
obj = (User)bf.Deserialize(stream);
stream.Flush();
stream.Close();
Console.Clear();
Console.WriteLine(obj.ToString());
Console.ReadLine();
}
}
Last edited: