Chào mọi người.

Mình có 1 bài tập là tạo 1 ứng dụng login quản lý người dùng.

Được chia ra làm 3 form: FormLogin, FormQuanly, FormDoiMatKhau.

1 lớp Users với users thì có chứa username, fullname, password, group.

Và đọc thông tin Users này từ 1 file có sẵn trong thư mục debug của bài tập.

Mình muốn hỏi là đọc dữ liệu thì không sao, nhưng khi ghi dữ liệu vào thì nó báo như thế:

The process cannot access the file 'D:\BT\C#\T1\bin\Debug\users\a.txt' because it is being used by another process.
Và đây là code ở FormDoiMatKhau của mình:
Mã:
private void btthaydoi_Click(object sender, EventArgs e)
{
            StreamReader sr = new StreamReader("users/" + username + ".txt");
            string s1 = sr.ReadLine();
            string s2 = sr.ReadLine();          
            if (s2 == txtmkc.Text)
            {            
                this.UUser = new Users(username);
                if (txtmkm.Text == txtnl.Text)
                {
                    _user.Password = txtmkm.Text;
                    StreamWriter sw = new StreamWriter("users/" + _user.UserName + ".txt"); //Báo lỗi tại dòng này
                    sw.WriteLine(_user.UserName);
                    sw.WriteLine(_user.Password);
                    sw.WriteLine(_user.FullName);
                    sw.WriteLine(_user.Group);
                    sw.Flush();
                    sw.Close();
                    
                    
                }
                else
                {
                    MessageBox.Show("Mật khẩu nhập lại không trùng khớp với mật khẩu mới", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Mật khẩu cũ không đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
}
Mong nhận được sự giúp đỡ từ mọi người. Cám ơn mọi người đã ghé qua xem cũng như là đã để lại những giải pháp ạ.

- - - Nội dung đã được cập nhật ngày 19-04-2014 lúc 06:41 PM - - -

Đã giải quyết được ạ. Lỗi nằm ở phần khác. Xin lỗi mọi người vì không đưa hết code nguồn lên.

Lần sau mình xin rút kinh nghiệm ạ.

Mong Mod có thể close bài hoặc xóa bài giúp mình ạ.

Cám ơn.