-1

enter image description here this login system working perfect.. but i need to change path as default.. currently it'z save on ' C' drive .. can to save inside debug folder. is it possible ?

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 == txtPass.Text)
     {
         MessageBox.Show("You are now successfully logged in |Welcome", "Success");

         frmMainMenu frm = new frmMainMenu();
         frm.Show();
         this.Hide();
     }
     else
     {
       MessageBox.Show("User Name Or Password Wrong!", "Error");
     }
 }
 catch (Exception ex)
 {
     MessageBox.Show(ex.Message);
 }
  • "can to save inside debug folder" -- Sounds like you are looking for `Environment.CurrentDirectory`, or maybe one of the ones [here](http://stackoverflow.com/questions/3991933/get-path-for-my-exe): `System.Reflection.Assembly.GetEntryAssembly().Location`, `AppDomain.CurrentDomain.BaseDirectory`, `Application.StartupPath` – Quantic May 10 '16 at 17:57
  • that's mean how to set default path file? where i run this software in different PC then this data file automatically store on that PC – Rifath Apps May 10 '16 at 18:23
  • Wait what exactly are you trying to do? It appears that you have a file under `C:\{username}\login.ID` which is storing {username}'s username and password in plain text? You really shouldn't do that. And you want to store this "data file" on a remote computer, a different computer than is running the code? You could use windows shares to do that.. but the premise of what you are trying to do is flawed (creating a "login system" using plain text files). – Quantic May 10 '16 at 18:32
  • http://i.stack.imgur.com/YIaLq.png please view this link... currently my username & password are stored in C drive. but i need change this one.. i need to save in debug folder . example login.txt or login.bin – Rifath Apps May 10 '16 at 18:48
  • 1
    Refresh your page and read the only answer here.. it will give you the full path to wherever your .exe is. `System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)` – Quantic May 10 '16 at 18:52

1 Answers1

2
var currentDirectory = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
The scion
  • 1,001
  • 9
  • 19