Home > other >  C# System.IO.DirectoryNotFoundException: Could not find a part of the path
C# System.IO.DirectoryNotFoundException: Could not find a part of the path

Time:11-24

        try
        {
             string directory = @"D:/user/user.txt";
             FileStream FS = new FileStream(directory, FileMode.Append);
             StreamWriter SW = new StreamWriter(FS);
             string register;
             register = $"{generateID()};{txtfirstName.Text};{txtLastName.Text};{txtUser.Text};{txtEmail.Text};{txtPersonalID.Text}";
             SW.WriteLine(register);
             SW.Close();
             FS.Close();
        }
        catch (Exception ex)
        {
             MessageBox.Show(ex.ToString());
        }

I run this code in c# windows forms .NET framework and constanly i get the same message. I am in university and i am pretty new in programming so i have no idea what could be wrong. What are your thoughs? Any idea?

enter image description here

  • Related