I use xml serialization for that sort of thing. There are tons of articles
all over the net and on msdn.microsoft.com that explain the ins and outs of
it. To briefly illustrate, here is some code samples (not production code
of course...but illustrative code).
// A simple user class to illustrate the idea
// "User.cs".
public class User
{
public bool ShowSplashScreen; // make sure we're public or add a
public property get/set
public string Name;
public User(string name)
{
ShowSplashScreen = true;
Name = name;
}
}
// Use something like this to load/save the user settings.
// You will need to add references to System.IO, System.Xml.Serialization,
and System.Windows.Forms
// "someclass.cs"
private User _MyUser;
.....
public bool LoadUserSettings()
{
string fileName = Application.UserAppDataPath + @"\usersettings.xml";
// UserAppDataPath ensures that it uses the logged on user's ApplicationData
folder.
if (File.Exists(fileName))
{
XmlSerializer ser = new XmlSerializer(typeof(User));
FileStream fs = new FileStream(fileName, FileMode.Open);
try
{
_MyUser = (User) ser.Deserialize(fs); // Note that you do not
need to create a new User first before trying to deserialize one.
return true;
}
finally
{
fs.Close();
}
return false;
}
public bool SaveUserSettings()
{
string fileName = Application.UserAppDataPath + @"\usersettings.xml";
XmlSerializer ser = new XmlSerializer(typeof(User));
FileStream fs = new FileStream(fileName, FileMode.Create);
try
{
ser.Serialize(fs, CurrentUser);
return true;
}
finally
{
fs.Close();
}
return false;
}
HTH,
ShaneB