views:

27

answers:

1

I have a WinForms application that checks for a TXT file in the application directory. There will be only a single line (user's email) or none. the code is like this:

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;
    }

This Seems to work except one really weird behaviour. When I uninstall the program, and re-install, it still finds the file and reads the previous e-mail. I checked the ApplicationDirectory there is no such file, searched Windows, whole C drive, there is noı mail.txt but it still finds and read the mail address that I have entered in the very first installation. Thanks in advance for any help.

A: 

First of all, you are making use of Application.Startup. This will return the path where the executable file is present. So, there is no question of looking file to some other location. As you are saying that you searched entire C drive, it's really a strange issue. I was facing similar issue with Windows Vista and Win 7. In these 2 operating systems, sometimes files get copied to "SysWow" folder as well.

Vijay Balkawade