hi everyone
this code is for edit a txt file but the there is no change in file can any one detect where is the error
this code is for edit a txt file but the there is no change in file can any one detect where is the error
private void button1_Click(object sender, EventArgs e)
{
Sname = textBox1.Text;
Spass = textBox2.Text;
ArrayList all = new ArrayList();
ArrayList name = new ArrayList();
ArrayList pass = new ArrayList();
int k=0,i;
try
{
StreamReader z = new StreamReader("D:\\users.txt");
while (true)
{
string line = z.ReadLine();
if (line == null)
{
z.Close();
break;
}
string[]words= line.Split(',');
all.Add(line);
name.Add(words[0]);
pass.Add(words[1]);
}
z.Close();
}
catch (FileNotFoundException)
{ MessageBox.Show("file not found"); }
for ( i = 0; i < name.Count; i++)
{
if (name.Contains(label3.Text) && pass.Contains(label6.Text))
{
k = pass.IndexOf(Spass);
break;
}
if (k < all.Count)
{
all.RemoveAt(k);
all.Insert(k, Sname + "," + Spass);
}
try
{
StreamWriter m = new StreamWriter("D:\\users.txt");
foreach (String s in all)
{ m.WriteLine(s);
}
m.Flush();
m.Close();
}
catch (FileNotFoundException)
{ MessageBox.Show("file not found"); }
}
this.Close();
}