public static void SaveVozila(Vozilo vozilo) { string path = HostingEnvironment.MapPath("~/App_Data/vozila.txt"); FileStream stream = new FileStream(path, FileMode.Create); StreamWriter sw = new StreamWriter(stream); int id = 0; foreach (Vozilo m in vozila) { sw.WriteLine(id + ";" + m.MarkaVozila + ";" + m.ModelVozila + ";" + m.TipVozila + ";" + m.BrojMestaUVozilu + ";" + m.DatumKadJeSlobodnoVozilo + ";" + m.CenaPoDanu + ";" + m.Status + ";" + m.Ulica + ";" + m.Broj + ";" + m.Mesto + ";" + m.PostanskiBroj + ";" + m.Poster + ";" + m.Obrisano + ";" + m.Aktivno + ";"); id++; } sw.Close(); stream.Close(); }
public static List <Vozilo> ReadProducts(string path) { vozila = new List <Vozilo>(); path = HostingEnvironment.MapPath(path); FileStream stream = new FileStream(path, FileMode.Open); StreamReader sr = new StreamReader(stream); string line = ""; while ((line = sr.ReadLine()) != null) { string[] tokens = line.Split(';'); Vozilo p = new Vozilo(int.Parse(tokens[0]), tokens[1], tokens[2], (TipVozila)Enum.Parse(typeof(TipVozila), tokens[3]), int.Parse(tokens[4]), DateTime.Parse(tokens[5]), int.Parse(tokens[6]), bool.Parse(tokens[7]), tokens[8], tokens[9], tokens[10], int.Parse(tokens[11]), tokens[12], bool.Parse(tokens[13]), bool.Parse(tokens[14])); vozila.Add(p); } sr.Close(); stream.Close(); return(vozila); }