1

Hi I am trying to find out what is the best location to save a cache file. I have an Windows form application that updates user's data from the server using a custom tool. I want to write the timestamp of the latest updates done on user's machine in the cache file. Where is the best location for keeping this file: 1. in application directory (c:\program files..) 2. in a temp location e.g. Users profile folder or c:\windows\temp 3. in any location (e.g. c:\dataupdates) where user has full access to read/write to.

1 Answers1

2

Not in the application directory. That much is clear. :) The application directory shouldn't even be writable by the program (or actually by the user account that runs the program). Although some applications still use this location, it has actually been deprecated since Windows 95, I believe, and it has become a real pain since the more rigid UAC applied in Windows Vista and 7.

So the most obvious options are:

  • The temp folder, which is for temporary files. Note however, that you will need to clean those files up. Temp folder is not automatically cleared by default, so adding new files all the time will consume increasingly much space on the hard drive. On the other hand, some users do clear their temp folders, or may have scripts installed that do that for them, so you cannot trust such files to remain. Also, this is not always C:\Temp of whatever. You'll have to ask Windows what the location is.
  • You can pick 'any' location. Note that you cannot write anywhere. You cannot even expect the C drive to exist. If you choose this, then you have to make it a configurable setting.
  • The %app data% directory, my personal favorite, which is a special directory for applications to store their data in. The advantage is, that you can ask Windows for this location, and you can make up a relative path based on that directory, so you don't really have to make it an application setting. For more info on how to get it, see also this question: C# getting the path of %AppData%

I would definitely choose the App Data path for this purpose.

Community
  • 1
  • 1
GolezTrol
  • 114,394
  • 18
  • 182
  • 210