简体   繁体   中英

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 program 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM