public void Save(DEventList oData) { FileStream fs = new FileStream(xmlPath, FileMode.Truncate, FileAccess.Write); XmlSerializer.Serialize(fs, oData); fs.Close(); }
private void LoadXml() { //DEventList list = new DEventList(); //DateTime date = new DateTime(2019, 3, 15); ; //DEvent d = new DEvent(); //d.StartTime = date; //d.EndTime = date; //d.Content = "Harry Potter"; //DEvents demo = new DEvents(); //demo.Date = date; //demo.Items.Add(d); //DEvent d2 = new DEvent(); //d2.StartTime = date; //d2.EndTime = date; //d2.Content = "Lord of The Rings"; //demo.Items.Add(d2); //list.EventList.Add(demo); //Save(list); try { FileStream fs = new FileStream(xmlPath, FileMode.Open, FileAccess.Read); EventList = (DEventList)XmlSerializer.Deserialize(fs); fs.Close(); } catch (Exception ex) { MessageBox.Show("Load xml error : " + ex.ToString()); } }