View Single Post
Old Jun 1st, 2011, 18:14:03   #11
Xyphos
Doing it wrong
 
Xyphos's Avatar
 
Join Date: Dec 2006
I haven't really looked at it, but I'm going to assume that the Win7 crash is UAC related;
The application might be getting a file permission denied error,
depending on where the user has the application extracted/ran from.

to remedy such a problem, it is wise to use the application data folder.

Code:
// C#
public static class SafeIO
{
  public static System.String AppData(System.String dataFile)
  {
     return System.String.Format("{0}\\{1}\\{2}\\{3}",
        System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), 
        System.Windows.Forms.Application.CompanyName,
        System.Windows.Forms.Application.ProductName,
        dataFile
     );
  }
}

//Example use:

string path = SafeIO.AppData("MyData.dat");

byte[] data = System.IO.File.ReadAllBytes(path);
on a Vista/7 system, the above would return
C:\Users\{user name}\Application Data\{company}\{product}\MyData.dat

in my case,
C:\Users\Xyphos\Application Data\Xyphos Software\TestApp\MyData.dat



...no clue how that would work in WinXP; but I'm sure you could tell me
__________________
"When life knocks you on your butt, you have to get back up and punch it in the face." --DJ Ashval of GSP

Nullified "Bitbucket" Deadcode - 220/25 Neut NanoMage Engi
Bits10 - 150/14 Clan Opifex Trader

Last edited by Xyphos; Jun 1st, 2011 at 18:26:12..
Xyphos is offline   Reply With Quote