views:

895

answers:

9

Please can someone advice what is the best place (path) to put some application data which should be accessible and editable by all users.

This is considering both Windows XP and Windows Vista and i expect that change in any file of above path does NOT trigger UAC!

+2  A: 
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

Should resolve to C:\Documents and Settings\All Users\Application Data\

From there, make subfolders such as MyCompany\MyApp

JC
+1  A: 

%ALLUSERSPROFILE%\Application Data\App
this is probably the only directory that all users can access without elevated privileges.

tloach
This is quite harcoded, and the "Application Data" folder could be in other language. Any way to internationalize the name of "Application Folder" ?
Romias
+1  A: 

If you're using .NET, Application.CommonAppDataPath should work.

Timothy Carter
isn't this winforms-only?
Pavel Radzivilovsky
+4  A: 

Plain Win API: SHGetFolderPath with CSIDL_COMMON_APPDATA as folder type.

Alex B
+1  A: 

If the users are not going to modify the data directly, and it will only be modified by the app, how about IsolatedStorage - http://msdn.microsoft.com/en-us/library/3ak841sy(VS.80).aspx

Paul Nearney
+1  A: 

Checkers provides the vital clue to do this in C or C++. So I have voted his answer.

Here are the details he left out:

// assumes
// company is a pointer to a character sting containing company name
// appname is a pointer to a character string containing application name
// fname   is a pointer to a character string cintaining name of file to be created

#include <shlobj.h>   // for SHGetFolderPath
#include <direct.h>   // for _mkdir

char path[MAX_PATH];
SHGetFolderPath(NULL,CSIDL_COMMON_APPDATA,NULL,NULL,path);
strcat(path,"/");
strcat(path,company);
_mkdir(path);
strcat(path,"/");
strcat(path,appname);
_mkdir(path);
strcat(path,"/");
strcat(path,fname);

// path is now a character string which can passed to fopen
ravenspoint
+1  A: 

If you're using .NET, Application.CommonAppDataPath should work. Also make sure that virtualization is turned off for your application

DotNET
A: 

You can also put it in a database.

tuinstoel