private MailBox readMailBox(string username) { string combinedPath = Path.Combine(_mainEmailsPath, "_" + username + "_" + "_mails.dat"); MailBox toRet; using (FileStream fileStream = new FileStream(combinedPath, FileMode.Open)) { //StringFormatter BinaryFormatter binaryFormatter = new BinaryFormatter(); try { toRet = (MailBox)binaryFormatter.Deserialize(fileStream); } catch (Exception) { toRet = new MailBox(); } } return toRet; }
private void writeMailBox(string username, MailBox mailBox) { string combinedPath = Path.Combine(_mainEmailsPath, "_" + username + "_" + "_mails.dat"); using (FileStream fileStream = new FileStream(combinedPath, FileMode.Create)) { //StringFormatter BinaryFormatter binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(fileStream, mailBox); } }
private void CreateMailsFileToNewUser(string username) { MailBox mailBox = new MailBox(); writeMailBox(username, mailBox); }