Iostream DoTeych Iostream DoTeych - 3 months ago 6
C# Question

C# help couldn't find the path (LOG IN SYSTEM)

So my program is working well but whenever i sign up on Form 2 it says that it couldn't find the path i don't know what's wrong please help i need to pass it later , i don't know if i need to make a new folder on the C: just to get the LOGIN.ID

{
public partial class Form1 : Form
{
public string username, password;
public Form1()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();

}

private void button1_Click(object sender, EventArgs e)
{
try
{
var sr = new System.IO.StreamReader("C\\" + textBox1.Text + "\\login.ID");
username = sr.ReadLine();
password = sr.ReadLine();
sr.Close();

if (username == textBox1.Text && password == textBox2.Text)
MessageBox.Show("Log-in Successfull", "Success!");
else
MessageBox.Show("Username or password is wrong! ","Error!");

}
catch (System.IO.DirectoryNotFoundException )
{
MessageBox.Show("The user doesn't exist!", "Error!");

}
}
}


}

//form 2

public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Hide();

}

private void button1_Click(object sender, EventArgs e)
{
try
{
var sw = new System.IO.StreamWriter ("C\\" + textBox1.Text + "\\login.ID");
sw.Write(textBox1.Text + "\n" + textBox2.Text);
sw.Close();

}
catch(System.IO.DriveNotFoundException )

{
System.IO.Directory.CreateDirectory("C:\\" + textBox1.Text);
var sw = new System.IO.StreamWriter("C\\" + textBox1.Text + "\\login.ID");
sw.Write(textBox1.Text + "\n" + textBox2.Text);
sw.Close();
}


}
}


}

Answer

You're missing the : after the C drive in many places in your code

var sw = new System.IO.StreamWriter("C\\" + textBox1.Text + "\\login.ID");

change to

var sw = new System.IO.StreamWriter("C:\\" + textBox1.Text + "\\login.ID");
Comments