Jump to content
Mark Williams

What's the best common folder for...

Recommended Posts

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:

  1. What is considered best practice for storing this sort of data?
  2.  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

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 by Stefan Glienke
  • Like 2
  • Thanks 1

Share this post


Link to post
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
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 🙂

  • Like 2

Share this post


Link to post
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

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
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
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
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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×