File not found on xp

I have a strange problem with a text file that I am sending with my application.

The file contains a bunch of sites when the program starts loading sites into an array.

On Windows 7, when I run the application, I do not get any errors. However, on XP I get c:\Document and setting\I\Application Data\fourmlinks.txt file not found. The strange part is that I created a text file with content and I put it in the application folder.

This is how I call in my code:

 string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\fourmlinks.txt"; 

My problem is that I cannot create a new file because it contains the basic data that the application requires and uses.

After the first run, the user can edit the file as much as he wants.

I'm not sure why this is happening, but it only happens on Windows XP.

How can I solve this problem?

EDIT


keyboardP suggests checking which windows start up, and then changing the path to it. so I came up with this code:

  System.OperatingSystem osInfo = System.Environment.OSVersion; if (osInfo.Platform == PlatformID.Win32NT) path = Environment.SpecialFolder.LocalApplicationData + "\\fourmlinks.txt"; else path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\fourmlinks.txt"; 

The problem is that even in Windows 7 I believe when I need to get false. is there any way to make sure that i am running on XP or Windows 7 in a diffrent way?


EDIT 2


using the operating system check, now I can be sure that I am Windows 7 or Windows XP. So, the code run appears again in Windows 7, but in Windows XP another error message appears:

enter image description here

I really have no idea how the path that I add to my program becomes the path that the error I'm asking for is talking about.

+6
source share
2 answers

In XP, try using Environment.SpecialFolder.LocalApplicationData .

Edit Comment

 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"; } } 
+1
source

To detect the current operating system, the user is working, you can use System.OperatingSystem , which consists of three components that apply to the following versions of Windows:

 +-----------------------------------------------------------------------------------------------------------------------------------------+ | | Windows | Windows | Windows |Windows NT| Windows | Windows | Windows | Windows | Windows | Windows | Windows | | | 95 | 98 | Me | 4.0 | 2000 | XP | 2003 | Vista | 2008 | 7 | 2008 R2 | +-----------------------------------------------------------------------------------------------------------------------------------------+ |PlatformID | Win32Windows | Win32Windows | Win32Windows | Win32NT | Win32NT | Win32NT | Win32NT | Win32NT | Win32NT | Win32NT | Win32NT | +-----------------------------------------------------------------------------------------------------------------------------------------+ |Major | | | | | | | | | | | | | version | 4 | 4 | 4 | 4 | 5 | 5 | 5 | 6 | 6 | 6 | 6 | +-----------------------------------------------------------------------------------------------------------------------------------------+ |Minor | | | | | | | | | | | | | version | 0 | 10 | 90 | 0 | 0 | 1 | 2 | 0 | 0 | 1 | 1 | +-----------------------------------------------------------------------------------------------------------------------------------------+ 

It is enough to know the versions of Major and Minor , since PlatFormID is Win32Windows or Win32NT

The following example shows how to use OperatingSystem to discover the current user operating system.

 int getOSArchitecture() { //Only required if you would like to show the user processor architecture (32-bit / 64-bit) string pa = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE"); return ((String.IsNullOrEmpty(pa) || String.Compare(pa, 0, "x86", 0, 3, true) == 0) ? 32 : 64); } string getOSInfo() { //Get Operating system information. OperatingSystem os = Environment.OSVersion; //Get version information about the os. Version vs = os.Version; //Variable to hold our return value string operatingSystem = ""; if (os.Platform == PlatformID.Win32Windows) { //This is a pre-NT version of Windows switch (vs.Minor) { case 0: operatingSystem = "95"; break; case 10: if (vs.Revision.ToString() == "2222A") operatingSystem = "98SE"; else operatingSystem = "98"; break; case 90: operatingSystem = "Me"; break; default: break; } } else if (os.Platform == PlatformID.Win32NT) { switch (vs.Major) { case 3: operatingSystem = "NT 3.51"; break; case 4: operatingSystem = "NT 4.0"; break; case 5: if (vs.Minor == 0) operatingSystem = "2000"; else operatingSystem = "XP"; break; case 6: if (vs.Minor == 0) operatingSystem = "Vista"; else operatingSystem = "7"; break; default: break; } } //Make sure we actually got something in our OS check //We don't want to just return " Service Pack 2" or " 32-bit" //That information is useless without the OS version. if (operatingSystem != "") { //Got something. Let prepend "Windows" and get more info. operatingSystem = "Windows " + operatingSystem; //See if there a service pack installed. if (os.ServicePack != "") { //Append it to the OS name. ie "Windows XP Service Pack 3" operatingSystem += " " + os.ServicePack; } //Append the OS architecture. ie "Windows XP Service Pack 3 32-bit" operatingSystem += " " + getOSArchitecture().ToString() + "-bit"; //Remove this if you do not want to show the processor architecture } //Return the information we've gathered. return operatingSystem; } 

Using the example published above, you will get, for example, Windows XP Service Pack 3 if the user runs Windows XP Service Pack 3 (SP3), if you call getOSInfo();


Running Windows 7 Service Pack 1 32-bit


thanks
Hope this helps :)

+3
source

All Articles