public IActionResult OnPost() { string Controllo = Request.Form["controlTelefono"]; string idRiga = Request.Form["rigaCancellare"]; if (Controllo != "fail") { string Nome = Request.Form["Nome"]; string Telefono = Request.Form["Telefono"]; try { DateTime Data = Convert.ToDateTime(Request.Form["Data"]); string Sum = System.IO.File.ReadAllText(Path); System.IO.File.WriteAllText(Path, Sum + Environment.NewLine + Nome + ";" + Telefono + ";" + Data.ToString("yyyy-MM-dd")); } catch { } } if (idRiga != "") { Dictionary <int, List <string> > MatriceRighe = new Dictionary <int, List <string> >(); //popolo il dizionario matrice dal file txt Testo = System.IO.File.ReadAllText(Path); string[] Tmprighe = Testo.Split(Environment.NewLine); int h = Tmprighe.Length; int f = 0; string Tmp; while (f < h) { Tmp = Tmprighe[f]; List <string> colonne = Tmp.Split(';').ToList(); //lista delle 3 colonne nome tel data MatriceRighe.Add(f, colonne); f += 1; } int id = Int32.Parse(idRiga); MatriceRighe.Remove(id); var csvLines = MatriceRighe.Values.Select(riga => string.Join(";", riga)); var csv = string.Join("\r\n", csvLines); System.IO.File.WriteAllText(Path, csv); } return(RedirectToPage("/Index")); }
public void OnGet() { //popolo il dizionario matrice dal file txt Testo = System.IO.File.ReadAllText(Path); string[] Tmprighe = Testo.Split(Environment.NewLine); int n = Tmprighe.Length; i = 0; string Tmp; while (i < n) { Tmp = Tmprighe[i]; List <string> colonne = Tmp.Split(';').ToList(); //lista delle 3 colonne nome tel data Matrice.Add(i, colonne); i += 1; } }