My wpf application has a login screen. The login screen consist of a combobox with a collection of people. I currently implemented a folder directory and text file creating upon initialization(if first time login) once the folder and file exist, it reads the file and based on the value that's saved, it'll load the correct user from the collection of people.
My question is this the most ideal way to do it? I'm wondering is there a better way to do it, I feel like this is a very old school method. Any tips would be greatly appreciated.
For example, if John Smith logs in - next time John starts the application, his name will automatically be the SelectedItem.
public void CacheInitialize()
{
var folderDirectory = System.AppDomain.CurrentDomain.BaseDirectory + "Cache";
var fileName = "UserCache.txt";
var fileDirectory = folderDirectory + "\\" + fileName;
if (!Directory.Exists(folderDirectory))
{
Directory.CreateDirectory(folderDirectory);
}
if (!File.Exists(fileDirectory))
{
File.WriteAllText(Path.Combine(folderDirectory, fileName), string.Empty);
return;
}
else
{
var filecontent = File.ReadAllText(Path.Combine(folderDirectory, fileName));
if (filecontent != string.Empty)
SelectedUser = Users.First(x => x.Id == int.Parse(filecontent));
}
}
public void CacheSave()
{
var folderDirectory = AppDomain.CurrentDomain.BaseDirectory + "Cache";
var fileName = "cache file3.txt";
var fileDirectory = folderDirectory + "\\" + fileName;
StreamWriter writer = new StreamWriter(fileDirectory);
writer.Write(SelectedUser.Id.ToString());
writer.Close();
}