Use 'ApplicationData' or 'LocalApplicationData' to store a file common to all users?
Asked Answered
G

1

10

Summary: Several different users will use my application on a specific machine. I want the application to store its data in a single common file on this machine regardless of which user is running the application.

To achieve what I want, I am wondering whether this question might be relevant: Difference between 'SpecialFolder.LocalApplicationData' and 'SpecialFolder.ApplicationData'?

From that question and its answers it appears that:

Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) 

is specific to the machine. Some of the information I have turned up by googling confirms that. However, I have also found information that says that LocalApplicationData is user specific.

So, which is true? And can anyone tell me what is really meant by "user specific" and "machine specific"?

Here's what I'm thinking: If LocalApplicationData is machine specific, then I can use that as a basis for having my application save all of its data to a single common file for all users.

I'm also wondering about the ApplicationData folder:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

Should I instead use ApplicationData to get what I want?

Giblet answered 12/3, 2013 at 15:48 Comment(4)
When in doubt read the documentation. CommonApplicationData.Merger
@RaymondChen why isn't this an answer, seeing as it's the answer?Devonne
Probably because it is not the answer, c:\programdata is not writable. The default install of Windows does not provide a folder that all users can write to. If this is important then you'll need to create one and give Everybody write access. You'll probably find out, later, that dealing with one user screwing up the data of another user and not having a backup can be quite a headache. Which is why file servers exist.Laurin
I have substantially edited your question to improve its focus and hopefully make it more useful to future readers. If you are unhappy with my revisions, please let me know.Scandinavian
G
8

Both ApplicationData and LocalApplicationData are only accessible to the currently logged-in user. The difference between these two is that ApplicationData is replicated and synchronized to other devices which the user is using in an enterprise environment. It would be used to store a user's preferences.

As Raymond suggested (see docs), you're going to want to use a different folder. CommonDocuments would be a good option for documents to be shared between all users. CommonMusic if you're storing music and so on...

If you're wanting to store application-specific files use:

Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
Glossolalia answered 21/4, 2015 at 18:47 Comment(1)
To put it short: Both are user-specific, and LocalApplicationData is also machine-specific.Sergent

© 2022 - 2024 — McMap. All rights reserved.