//** SaveRecordset ** //Save a list to a XML file public void SaveRecordset <T>(List <T> recToSave, string tableName) { CSConfig _config = new CSConfig(); string path = _config.GetFullPath(CSConfig.PathTypeEnum.DatabasePath) + "/" + tableName + ".xml"; XmlSerializer writer = new XmlSerializer(typeof(List <T>)); FileStream file = File.Create(path); writer.Serialize(file, recToSave); file.Close(); }
//** GetRecordset ** // Load a list from a XML file public List <T> GetRecordset <T> (string tableName) { CSConfig _config = new CSConfig(); //List to be returned List <T> toReturn = new List <T> (); //Create the path to file string path = _config.GetFullPath(CSConfig.PathTypeEnum.DatabasePath) + "/" + tableName + ".xml"; if (File.Exists(path)) { XmlSerializer reader = new XmlSerializer(typeof(List <T>)); StreamReader file = new StreamReader(path); toReturn = (List <T>)reader.Deserialize(file); file.Close(); } return(toReturn); }