Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
private void Login_btn_Click(object sender, EventArgs e)
        {
            User u1 = new User();
            u1.Username = Username_login_Textbox.Text;
            u1.Password = Password_login_Textbox.Text;

            FileStream fs1 = new FileStream(@"C:\Users\QEBO\Desktop\Exam_System_Users\test.txt", FileMode.OpenOrCreate, FileAccess.Write);
            BinaryReader br = new BinaryReader(fs1); // here appears THE STREAM WAS NOT READABLE :(

            if (u1.Username == fs1.Length.ToString())
            {
                if (u1.Password == fs1.Length.ToString())
                {
                    ExamSystem es = new ExamSystem();
                    es.ShowDialog();
                }
            }
            else
            {
                MessageBox.Show("Invalid username or password");
            }
            fs1.Flush();
            fs1.Close();
            br.Close();
        }
Posted
Updated 13-Jun-12 8:21am
v4

I'm guessing the issue is that you open the stream to write, then attempt to read it.

Try this instead:
C#
FileStream fs1 = new FileStream(@"C:\Users\QEBO\Desktop\Exam_System_Users\test.txt", FileMode.OpenOrCreate, FileAccess.Read);
BinaryReader br = new BinaryReader(fs1);
 
Share this answer
 
Downvoted for the abolsutley childish subject line and you didn't even ask a question. Putting a comment in the code isn't exactly what I would call a question.

But, from the code snippet, you opened the file for Write only access, then tried to read the file. with a BinaryReader. Do you see a problem with that??
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900