public void LoadSettings() { FileInfo settings = new FileInfo("test.txt"); if (settings != null && settings.Exists && settings.Length != 0) { SaveInfo info = new SaveInfo(); // Tell the XmlSerializer which types we will be deserializing Type[] typeArray = new Type[1]; typeArray[0] = typeof(SaveInfo); StreamReader reader = new StreamReader("test.txt"); if (reader != null) { try { // Check if we have a valid file to read? if (reader.Peek() > -1) { // Extract the serialized MOG_ShutdownInfo object XmlSerializer serializer = new XmlSerializer(typeof(SaveInfo), typeArray); info = serializer.Deserialize(reader) as SaveInfo; } foreach (NodeData remoteData in info.data) { LoadNodeSettings(remoteData, RemoteProjectsTreeView.Nodes); } } catch (Exception e) { // JohnRen - Don't tell the user about this since there is nothing they can do about it e.ToString(); } finally { reader.Close(); } } } }
public bool SaveSettings() { try { // Open the file specified for output and serialize the lists TextWriter writer = new StreamWriter("test.txt"); if (writer != null) { // Tell the XmlSerializer which types we will be serializing Type[] typeArray = new Type[1]; typeArray[0] = typeof(SaveInfo); // Serialize the data XmlSerializer serializer = new XmlSerializer(typeof(SaveInfo), typeArray); SaveInfo info = new SaveInfo(); SaveNodeSettings(info.data, RemoteProjectsTreeView.Nodes); serializer.Serialize(writer, info.data); writer.Flush(); writer.Close(); // Success return(true); } } catch (Exception e) { e.ToString(); } finally { } return(false); }