views:

51

answers:

2

I have this code:

public static string GetUserEmail()
{
    string path = Application.StartupPath + "\\mail.txt";
    MessageBox.Show(path);
   string adres = String.Empty;
   if (File.Exists(path))
    {
        using (StreamReader sr = new StreamReader(path))
        {
            adres = sr.ReadLine();
        }
    }
   else
   {
       using (FileStream fs = File.Create(path))
       {
           using (StreamReader sr = new StreamReader(path))
           {
               adres = sr.ReadLine();
           }
       }

   }
   MessageBox.Show(adres);
    return adres;
}

I checked the ApplicationPath with the MessageBox.Show(); as you can see, go there and delete the file, re-launch the app, and it still reads the previous line . I uninstall the app re-install and still seems to find the file and read the same line I have entered in the very first installation. I searched windows, the whole C drive, there is no mail.txt and it still finds the mail.txt and reads the line (a email address, used to identify the user)

What can it be? aliens?

A: 

Do you have any code elsewhere that creates and writes the file, as part of the application startup?

Otherwise, its definitely aliens.

ck
+1  A: 

Firstly, which code route does the program take? The one where the file is created, or the one where the existing file is read?

Try placing a breakpoint just before the existance of the file is checked and then go and check at that point if the file exists or not.

Kragen