public void SaveFormStates(SaveStatesEventArgs e) { if (System.IO.File.Exists(FilePath)) { if (!this.Overwrite) { throw new Exception("File exists already."); } System.IO.File.Delete(FilePath); } try { DataContractSerializer serializer = new DataContractSerializer(typeof(StateContainer)); using (var sw = new StreamWriter(this.FilePath)) { using (var writer = new XmlTextWriter(sw)) { writer.Formatting = Formatting.Indented; // indent the Xml so it’s human readable serializer.WriteObject(writer, e.States); writer.Flush(); } } } catch { } }
public void SaveFormStates(SaveStatesEventArgs e) { if (System.IO.File.Exists(FilePath)) { if (!this.Overwrite) { throw new Exception("File exists already."); } System.IO.File.Delete(FilePath); } try { var content = Newtonsoft.Json.JsonConvert.SerializeObject(e.States, Formatting.Indented, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple }); System.IO.File.WriteAllText(FilePath, content); } catch { } }
public void SaveFormStates(SaveStatesEventArgs e) { if (System.IO.File.Exists(FilePath)) { if (!this.Overwrite) { throw new Exception("File exists already."); } System.IO.File.Delete(FilePath); } try { var content = Newtonsoft.Json.JsonConvert.SerializeObject(e.States, Formatting.Indented); System.IO.File.WriteAllText(FilePath, content); } catch { } }