I just finished my application - it works properly when im trying to open it on different computer im suffering this problem (after opening the exe file):
System.UnauthorizedAccessException: Access to file is denied
'C:\Program Files\BBO Generator\database.dat'.
in System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
in System.IO.FileStream.Init(String path, FileMode mode, FileAccess
access, Int32 rights, Boolean useRights, FileShare share, Int32
bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String
msgPath, Boolean bFromProxy)
etc...
the program works with several files, based on StreamWriter/Reader (Writer and Reader are declared in different method of my class):
that happend on VISTA, to be honest i have no idea about its security managment (im xp fan)...
anyway, what about FileAttributes Method (System::IO::File) ?
Maybe this will solve it once and for all ? (pity i can't test it :)
The question is if i assign attributes manualy to my files(arent they read/write available by default?) will it change anything if the folder (here program files, lets us be stubborn) is set to read only...
As I understand it (more so with Vista), the files in ‘Program Files’ are not writable by non-administrative programs. UAC will even block a program run by an administrator from writing into the files.
Here are a number of possible solutions:
Probably the best would be to store your data files in a non-restricted folder, something like the users profile folder, or maybe the CommonApplicationData* folder.
Use ‘Run as administrator’ to run the program with administrative rights. This would be a good test to see if it is a rights issue.
Finally (worse) would be to change the security on the folder to give your user account write permissions.
HTH
---------------------------------
*CommonApplicationData: A system special folders that serves as a common repository for application-specific data that is used by all users. Use Environment::GetFolderPath () to obtain the path.