public static void SaveToFile(object t, string fileName) { try { using (MemoryStream memStream = new MemoryStream()) { DataContractSerializer serializer = new DataContractSerializer(t.GetType()); //foreach (StopOrder order in orderList) { serializer.WriteObject(memStream, t); } // Encrypt the memory stream. byte[] encryptedData = Encryption.EncryptData(memStream.ToArray()); // Write encrypted credentials to the file and ACL the file simultaneously. using (FileStream stream = new FileStream(fileName, FileMode.Create)) { stream.Write(encryptedData, 0, encryptedData.Length); } } } catch (Exception ex) { } }
public static void SaveToFile(Config config, string fileName) { using (MemoryStream memStream = new MemoryStream()) { DataContractSerializer serializer = new DataContractSerializer(typeof(Config)); serializer.WriteObject(memStream, config); // Encrypt the memory stream. byte[] encryptedData = Encryption.EncryptData(memStream.ToArray()); using (FileStream stream = new FileStream(fileName, FileMode.Create)) { stream.Write(encryptedData, 0, encryptedData.Length); } } }