Reputation: 27
in my program, user names and passwords are coming from text files. I want to update the password by pressing a button when necessary, what can I do for this?
private void Form1_Load(object sender, EventArgs e)
{
this.IsMdiContainer = true;
string[] firmalar = System.IO.File.ReadAllLines(@"Data\\sirket.txt", System.Text.Encoding.GetEncoding("UTF-8"));
foreach (string str in firmalar)
{
SirketList.Items.Add(str);
}
string[] kullanici = System.IO.File.ReadAllLines(@"Data\\kullanici.txt", System.Text.Encoding.GetEncoding("UTF-8"));
foreach (string str in kullanici)
{
KullaniciList.Items.Add(str);
}
string[] kod = System.IO.File.ReadAllLines(@"Data\\kod.txt", System.Text.Encoding.GetEncoding("UTF-8"));
foreach (string str in kod)
{
kodList.Items.Add(str);
}
string[] sistem = System.IO.File.ReadAllLines(@"Data\\sistem.txt", System.Text.Encoding.GetEncoding("UTF-8"));
foreach (string str in sistem)
{
sistemList.Items.Add(str);
}
string[] isveren = System.IO.File.ReadAllLines(@"Data\\isveren.txt", System.Text.Encoding.GetEncoding("UTF-8"));
foreach (string str in isveren)
{
isverenList.Items.Add(str);
}
string[] araci = System.IO.File.ReadAllLines(@"Data\\araci.txt", System.Text.Encoding.GetEncoding("UTF-8"));
foreach (string str in araci)
{
ListAraci.Items.Add(str);
}
}
Upvotes: 0
Views: 148
Reputation: 21
If I were you, I would store all this information in a single file. And the data would be located line by line. Then I would read it by dividing it by lines as I read, change the new value and rewrite it
Upvotes: 1
Reputation: 1084
File static class is your friend here.
Seems you use different files for each one of the properties you want to load/save, so you should bind to your save button code that looks like this:
public static async Task SavePasswordAsync()
{
await File.WriteAllTextAsync(kodList, text);
}
Upvotes: 2