public void AddToFile(Alumno al) { //string path = @"C:\Users\enric.pedros\Desktop\alumnes.txt"; string path = ConfigurationManager.AppSettings["ConfigPathTxt"].ToString(); //string stringtoappend = al.Nombre + "," + al.Id + "," + al.Edad + "," + al.Dni + "," + al.Al_Guid; try { // File.AppendAllText(path, toappend); + Environment.NewLine if (File.Exists(path)) { using (StreamWriter strw = File.AppendText(path)) { strw.WriteLine(al.ToString()); } } else { } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public void AƱadir(Alumno alumno) { using (StreamWriter sw = File.AppendText(Ruta)) { sw.WriteLine(alumno.ToString()); } }
public static Alumno NewStudent() { Alumno al = null; string nom, dni; Console.WriteLine("Write the name:"); nom = Console.ReadLine(); Console.WriteLine("Write the id:"); Int32.TryParse(Console.ReadLine(), out int id); Console.WriteLine("Write the age:"); Int32.TryParse(Console.ReadLine(), out int age); Console.WriteLine("Write the dni:"); dni = Console.ReadLine(); al = new Alumno(nom, age, id, dni); Console.WriteLine(al.ToString()); return(al); }