public void Save(DDiarys oData) { FileStream fs = new FileStream(xmlPath, FileMode.Truncate, FileAccess.ReadWrite); XmlSerializerDDiarys.Serialize(fs, oData); fs.Close(); }
private void LoadXml() { //DDiary d = new DDiary(); //d.InputDateTime = new DateTime(2019, 3, 15); //d.Name = "20190315"; //d.Content = "ceshi"; //DDiarys demo = new DDiarys(); //demo.Items.Add(d); //demo.Items.Add(d); //Save(demo); //Diarys = demo; try { FileStream fs = new FileStream(xmlPath, FileMode.Open, FileAccess.Read); Diarys = (DDiarys)XmlSerializerDDiarys.Deserialize(fs); fs.Close(); } catch (Exception ex) { MessageBox.Show("Load xml error : " + ex.ToString()); } }