The program cannot find the file after installation

I created a program that uses a ready-made text file containing a list of sites. Now on some computer the program works fine, but on my other computer this is not so.

I test the program on 2 of my computers with Windows 7, and 1 xp and I do not have any errors. This program has been used for some time on XP, now my friend wants to install it on his Windows 7 computer at home, but the program does not find the file after installing the program.

this is the error he gets:

System.IO.FileNotFoundException: file not found 'C:\Users\eli\AppData\Roaming\fourmlinks.txt'.
file name: 'C:\Users\eli\AppData\Roaming\fourmlinks.txt'

The fact is that I send this file to the main program folder (application files), and it still cannot find it.

This is the code I use to search for a file when the program starts:

sring path = "";
path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\fourmlinks.txt";
            System.OperatingSystem osInfo = System.Environment.OSVersion;
            if (osInfo.Platform == PlatformID.Win32NT)
            {
                if (osInfo.Version.Major == 5 && osInfo.Version.Minor != 0)
                {
                    //running XP
                    //path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\fourmlinks.txt";
                    path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\fourmlinks.txt";
                }
            } 

, , Windows 7 Windows XP.

: -, ( 7 XP). , .

:

  • , - , ?
  • , ?

( )

+1
1
, - , - ?

- , - . , :

file not found 'C:\Users\eli\AppData\Roaming\fourmlinks.txt'

""; , .

,

? , , . " ...", , .

string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "fourmlinks.txt");

, . "fourmlinks.txt" , - , , , .

string path = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
    "fourmlinks.txt");

. - , , - . - , .

, GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)? , . GetExecutingAssembly().Location , , . , , . , .

, , Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData). , , . System.Reflection.Assembly.GetExecutingAssembly().Location. - :

string fileName = "fourmlinks.txt";
string target = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileName);
if (!File.Exists(target))
{
    string source = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), fileName);
    File.Copy(source, target);
}

GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) , ; , .

, , , Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).

+5

All Articles