0

I am storing .dat files in ProgramData to write and read configurations about my software. I can read, but I can't write. These .dat files are copied when software is installed. The installer has been created with AwInstall.

CODE TO WRITE .DAT:

If File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) & "\NameSoftware\Configuration\paramsBiz.dat") = True Then
            Dim sw As StreamWriter = New StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) & "\NameSoftware\Configuration\paramsBiz.dat")
            sw.Write(myString)
            sw.Close()
            sw = Nothing
            Return True
        Else
            Return False
        End If

ERROR: I am getting this error:

System.UnauthorizedAccessException: Acceso denegado a la ruta de acceso 'C:\ProgramData\NameSoftware\Configuration\paramsBiz.dat'.
   en System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   en 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)
   en System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   en System.IO.StreamWriter.CreateFile(String path, Boolean append)
   en System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
   en System.IO.StreamWriter..ctor(String path)

UPDATE 1:

ok, is a problem with this directory ProgramData, as has been said Hans Passant

But alternative path could be used to store data and that any user (admin or not) can read and write these files?

kontable
  • 73
  • 9
  • 3
    This is entirely normal, programs only have read-only access to ProgramData. A pretty empty directory, doesn't have much beyond spelling dictionaries. You must use AppData instead. – Hans Passant May 04 '15 at 14:55
  • Users / Default / AppData / Local / [folder software] / will common for all users? – kontable May 04 '15 at 16:03
  • And is safe path to store databases? With read and write rights – kontable May 04 '15 at 16:30
  • Or Or it would be better to use this directory c:/Users/Public/ to save config files and database? – kontable May 04 '15 at 16:39
  • Where depends on if there is a single logged I user on a desktop - if so AppData for the user is fine. 'Public' is not a good idea - All Users is better but hard to get to. I'd just create a folder for the app on C:\MyApp\... – rheitzman May 04 '15 at 19:57
  • Store database and dat files in c:\MyApp\ It will not bring right problems? Because all users (admin and not admin) need write them – kontable May 04 '15 at 21:48

0 Answers0