[C#] [.NET] Lecture d'une classe dans un fichier
bonjour,
j'enregistre les options de mon logiciel dans un fichier dont j'ai donné comme extension .cfd
J'ai créer une classe qui contient toutes les options (pour l'instant juste le path de ma bdd). J'enregistre les options dans mon fichier ainsi :
Code:
1 2 3 4 5 6
| public void SauverOption()
{
IFormatter formatter = new BinaryFormatter();
Stream strm = new FileStream(Application.StartupPath + "\\Options1.cfd", FileMode.Create, FileAccess.Write);
formatter.Serialize(strm, MesOptions); strm.Close();
} |
où "Options1.cfd" est mon fichier config et "MesOptions" la classe qui contient les infos.
Et voici comment je fais pour recuperer ma config au lancement du logiciel:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| public int ChargerOption()
{
if(!File.Exists(Application.StartupPath + "\\Options.cfd"))
{
return -1;
}
else
{
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream(Application.StartupPath + "\\Options.cfd", FileMode.Open, FileAccess.Read);
MyOption = (ClassOption) formatter.Deserialize(stream);
stream.Close();
return 1;
}
} |
Il n'y a aucun message d'erreur mais je ne recupère rien dans ma classe!
Qu-est-ce qui ne va pas?