How to save a username in a C# windows application in a temp file?
After the user logins in the program, I want that my program remembers the username of the last user and when the p开发者_开发问答rogram reopens, the username filed is filled automatically with the username of that last user.
I want to know how to save and restore username. I dont want to use a database.
A better solution than temporary files is simply to use application settings.
To set the last username:
Properties.Settings.Default.LastUsername = theUsername;
Properties.Settings.Default.Save();
Then you can access Properties.Settings.Default.LastUsername
any time you want to use the last username.
System.IO.File.WriteAllText(path, Environment.UserName);
System.IO.File.ReadAllText(path);
Something like that should work i did not wrote the code.
精彩评论