private void LoadXml() { //DCollectionList list = new DCollectionList(); //DateTime date = new DateTime(2019, 3, 15); ; //DCollectionItem d = new DCollectionItem(); //d.InputDateTime = date; //d.Name = "Harry Potter"; //List<DCollectionItem> demo = new List<DCollectionItem>(); //demo.Add(d); //DCollectionItem d2 = new DCollectionItem(); //d2.InputDateTime = date; //d2.Name = "Gundam Seed"; //demo.Add(d2); //list.List.Add(demo); //Save(list); try { FileStream fs = new FileStream(xmlPath, FileMode.Open, FileAccess.Read); CollectionList = (DCollectionList)XmlSerializer.Deserialize(fs); fs.Close(); } catch (Exception ex) { MessageBox.Show("Load xml error : " + ex.ToString()); } }
public void Save(DCollectionList oData) { FileStream fs = new FileStream(xmlPath, FileMode.Truncate, FileAccess.Write); XmlSerializer.Serialize(fs, oData); fs.Close(); }