I am creating a program that encrypts/hashs messages
I have a list that contains (date,user,encryption, message,encryptedmessage)
=> Variables.oHistorique.Liste_historique.
When I just encrypt messages then save it works fine, when I open that file the list contains all the information expected however if I open a file then re-save it (even under a new name) it’s empty, the list is empty.
I appreciate all the help i can get
Thanks
P.S
I’ve checked and the list is populated when I save but not when i open the newly saved file
//when i click open
private void ouvrirToolStripMenuItem_Click(object sender, EventArgs e)
{
FileDialog location = new OpenFileDialog();
location.Filter = "Data Files (*.dat)|*.dat";
location.FilterIndex = 1;
result = location.ShowDialog();
if (result == DialogResult.OK)
{
dataGridView1.Rows.Clear();
Variables.oHistorique = (CHistorique)oSerialize.DeSerializeObject(location.FileName);
for (int i = 0; i < Variables.oHistorique.Liste_historique.ToArray().Length; i++)
{
dataGridView1.Rows.Add(Variables.oHistorique.Liste_historique[i].Date, Variables.oHistorique.Liste_historique[i].User, Variables.oHistorique.Liste_historique[i].Type, Variables.oHistorique.Liste_historique[i].Chaine, Variables.oHistorique.Liste_historique[i].ChaineCrypt);
}
dataGridView1.CurrentCell = null;
}
}
//When I click on save :
private void sauvgarderToolStripMenuItem_Click(object sender, EventArgs e)
{
FileDialog location = new SaveFileDialog();
location.Filter = "Data Files (*.dat)|*.dat";
location.FilterIndex = 1;
result = location.ShowDialog();
if (result == DialogResult.OK)
{
oSerialize.SerializeObject(CHistorique.GetInstance(),location.FileName);
}
}
//Here’s my class Serialize
class CSerialize
{
private static CSerialize Instance;
private CSerialize()
{
}
public void SerializeObject(object o, string file)
{
Stream stream = File.Open(file, FileMode.Create);
BinaryFormatter b = new BinaryFormatter();
b.Serialize(stream, o);
stream.Close();
}
public object DeSerializeObject(string file)
{
Object o;
Stream stream = File.Open(file, FileMode.Open);
BinaryFormatter b = new BinaryFormatter();
o = b.Deserialize(stream);
stream.Close();
return o;
}
public static CSerialize GetInstance()
{
if (Instance == null)
{
Instance = new CSerialize();
}
return Instance;
}
}
I found the answer
I replaced
with