Finding the best folder for all users on a Windows computer

We are creating a game that will soon add a level editor function. We want the user to be able to set the levels that he uploaded to the folder, and then play them in the game without any hassle. So, we are looking for a folder that anyone can find, open, write, read and multi-user. In Windows Vista / 7, the / Users / Public / folder looks like a great candidate. However, it is not listed in the .net enum System.Environment.SpecialFolder. I went through all of them and checked what they give in different versions of Windows, and no one meets my requirements.

I found Environment.SpecialFolder.CommonApplicationData that works, but this folder is hidden (C: \ ProgramData), and I assume that most users do not display hidden folders.

As it seems now, we will need to solve the problem with the folder of personal documents, but we would really like the folder with several users.

Does anyone have any clues?

(Hard coding c: \ Users \ Public \ is out of the question, it will work only on English systems)

+7
c #
source share
4 answers

Doug Hennig on finding a path for C: \ Users \ Public :

There is no CSIDL value in this folder, but the PUBLIC environment variable is specified for it, so you can use GETENV ('PUBLIC') to determine your location. By default, this variable contains C: \ Users \ Public in Windows Vista. The variable does not exist in Windows XP, so your code should handle the case where GETENV ('PUBLIC') returns an empty value.

Alternatively, you can use the parent of the folder specified by CSIDL_COMMON_DOCUMENTS, which provides C: \ Documents and Settings \ All Users \ Documents in XP and C: \ Users \ Public \ Documents in Vista.

I think Environment.SpecialFolder.CommonDocuments might be the right place for your files.

+8
source share

The following should return C:\Users\Public\Documents\ in Vista / Win7 and C:\Documents and Settings\All Users\Documents for previous OS.

 [System.Runtime.InteropServices.DllImport("shell32.dll")] static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, uint dwFlags, [Out] StringBuilder pszPath); public string GetSharedDocsFolder() { StringBuilder sb = new StringBuilder(); int CommonDocumentsFolder = 0x002e; SHGetFolderPath(IntPtr.Zero, CommonDocumentsFolder, IntPtr.Zero, 0x0000, sb); return sb.ToString(); } 
+4
source share

Could you put the folder in the application directory and then create a shortcut for it for each user (when they first use this feature) in your home directory? I know this is not exactly a โ€œuniversalโ€ pre-existing folder that you might want, but will it work anyway?

+1
source share

This can help. View Post:

In Windows Vista or later:

% PUBLIC% C: \ Users \ Public

In Windows XP:

 %ALLUSERSPROFILE% C:\Documents and Settings\All Users 
0
source share

All Articles