Mark Williams 14 Posted January 10, 2020 From within an app I save data obtained over the internet from a database to a local file so that when the user needs to reopen it can be loaded locally rather than across the net. Also, the user can save other data they are working on for later restoration. My inclination is to place these file in "C:\ProgramData" (CSIDL_COMMON_APPDATA), but I notice Embarcadero, for example, save new projects off "C:\Users\Public\Public Documents". Foxit also use it. Two questions: What is considered best practice for storing this sort of data? How do you get the "C:\Users\Public\Public Documents"? There doesn't appear to be a constant value to use with SHGetFolderPathA to get it. All I can find is CSIDL_COMMON_DOCUMENTS and that gets "C:\User\Public\Documents", which doesn't exist on my version of Windows10. Share this post Link to post
Stefan Glienke 2019 Posted January 10, 2020 (edited) There is no C:\Users\Public\Public Documents - that's just how they get displayed in the explorer - click into the address bar and you see its C:\Users\Public\Documents (by default - it can be anywhere else) Is the file ... for the program itself and ... only on this machine and for every user -> %programdata%\<program name> only on this machine and only for current user -> %localappdata%\<program name> available on other machines for the current user -> %appdata%\<program name> some document/file for the current user only -> %userprofile%\documents something that should be available for other users on this machine as well -> public documents (I think there is no variable by default for that, only for the public folder, but the public documents can actually stored somewhere else, I think registry holds that information) Edited January 10, 2020 by Stefan Glienke 2 1 Share this post Link to post
Mark Williams 14 Posted January 10, 2020 3 minutes ago, Stefan Glienke said: There is no C:\Users\Public\Public Documents - that's just how they get displayed in the explorer - click into the address bar and you see its C:\Users\Public\Documents (by default - it can be anywhere else) Damn tricky fellas! I should have realised that! It's the third option. So I will place in Public Documents ShellGetFolderPath(CSIDL_COMMON_DOCUMENTS, Path); path := includeTrailingPathDelimiter(path); stream.saveToFile(path+'stream.txt'); Saves to C:\Users\Public\Public Documents' . So all is good. I don't actually want users to try and open the files directly from the folder. My app just needs to know where they are so it can build a list of them (FindFirst...) and offer them via the app for opening. They could be anywhere as far as the app is concerned, it just needs to know how to find them. Share this post Link to post
FredS 138 Posted January 10, 2020 34 minutes ago, Mark Williams said: don't actually want users to try and open the files directly from the folder. Stefan covered that under 'for the program itself ', don't clutter up Documents with stuff that isn't for the user's end use.. annoying 🙂 2 Share this post Link to post
Mark Williams 14 Posted January 10, 2020 11 minutes ago, FredS said: Stefan covered that under 'for the program itself ', don't clutter up Documents with stuff that isn't for the user's end use.. annoying 🙂 Ah yes! Thanks Share this post Link to post
aehimself 399 Posted January 10, 2020 I also started to use %USERPROFILE% and %APPDATA% as local data storages. If people want to exchange their information, they can export and import; but not necessarily everyone wants to see the same information. Just imagine your application running on a terminal server used by 100+. They will surely want to separate their data. Share this post Link to post
Mark Williams 14 Posted January 10, 2020 8 minutes ago, aehimself said: Just imagine your application running on a terminal server used by 100+. They will surely want to separate their data. I don't actually want them to know where the data is and I also want it to be shared amongst anyone else who has access to the app, but only via my app. Share this post Link to post
Remy Lebeau 1436 Posted January 12, 2020 On 1/10/2020 at 1:39 PM, Mark Williams said: I don't actually want them to know where the data is and I also want it to be shared amongst anyone else who has access to the app, but only via my app. Then CSIDL_COMMON_APPDATA/FOLDERID_ProgramData is appropriate. Share this post Link to post
Mark Williams 14 Posted January 14, 2020 On 1/12/2020 at 7:38 PM, Remy Lebeau said: Then CSIDL_COMMON_APPDATA/FOLDERID_ProgramData is appropriate. That's what I've opted for. Thanks. Share this post Link to post
A.M. Hoornweg 144 Posted January 14, 2020 On 1/10/2020 at 6:33 PM, Stefan Glienke said: Is the file ... available on other machines for the current user -> %appdata%\<program name> Hi Stefan, do you know if that folder is only for domain users? Or are there other scenarios in which that folder is synced between machines? Share this post Link to post
Stefan Glienke 2019 Posted January 14, 2020 1 hour ago, A.M. Hoornweg said: if that folder is only for domain users? I think so but I would rather consult the Windows documentation on roaming profiles to be sure. Share this post Link to post