Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save a username in a C# windows application in a temp file?

Tags:

c#

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.

like image 903
Iman Avatar asked Dec 08 '25 02:12

Iman


2 Answers

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.

like image 100
Ry- Avatar answered Dec 10 '25 14:12

Ry-


System.IO.File.WriteAllText(path, Environment.UserName);
System.IO.File.ReadAllText(path);

Something like that should work i did not wrote the code.

like image 35
Rene de la garza Avatar answered Dec 10 '25 15:12

Rene de la garza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!