8

We are making a game which will add a level editor feature soon. We want the user to be able to put levels he's downloaded in a folder and then play it in the game, without any hassle. So, we're looking for a folder that anybody can find, open, write, read, and is multiuser. On Windows Vista / 7, the folder /Users/Public/ look like a great candidate. However, It's not listed in the .net enum System.Environment.SpecialFolder. I have went through them all, and checked what they yield on different Windows versions, and none live up to my requirements.

I did find Environment.SpecialFolder.CommonApplicationData, that kinda works, but that folder is hidden (C:\ProgramData) and I assume most users don't display hidden folders.

As it stands now, it looks like we'll have to settle for the personal documents folder, but we'd really like a multi user folder.

Anyone have any tips?

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

reallyjoel
  • 83
  • 1
  • 5

4 Answers4

9

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

There isn’t a CSIDL value for this folder, but the environment variable PUBLIC points to it, so you can use GETENV('PUBLIC') to determine its location. By default, this variable contains C:\Users\Public in Windows Vista. The variable doesn't exist in Windows XP, so your code must handle the case where GETENV('PUBLIC') returns a blank value.

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

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

Community
  • 1
  • 1
Colin Pickard
  • 45,724
  • 13
  • 98
  • 148
  • CommonDocuments sounds awesome, however it's .net 4.0, and I'm using mono 1.2.5 (which is like .net 2.0), so I'll have to make somthing like the above. Thanks. – reallyjoel Mar 09 '10 at 08:20
  • CSIDL_COMMON_DOCUMENTS is the appropriate CSIDL value. – ur. Oct 26 '11 at 06:51
4

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

[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();
}
C-Pound Guru
  • 15,967
  • 6
  • 46
  • 67
  • 1
    Note that by default all users can write to this location, but users cannot write to files or folders created by a different user. If you want multiple non-administrator users to be able to modify the same file, you have to manage permissions explicitly - regardless of where you create the file/folder in the filing system. – Ian Goldby Jan 25 '11 at 11:46
1

Could you put a folder in the application's directory, then create a shortcut to it for every user (when they first use the feature) in their home directory? I know it's not quite the "Universal" pre-existing folder you may have wanted, but would this work anyway?

FrustratedWithFormsDesigner
  • 26,726
  • 31
  • 139
  • 202
0

This may help. See this Post:

  1. http://msdn.microsoft.com/en-us/library/bb762584%28VS.85%29.aspx

  2. Location of %allusersprofile% folder in Windows Vista?

In Windows Vista or later:

%PUBLIC% C:\Users\Public

In Windows XP:

%ALLUSERSPROFILE%   C:\Documents and Settings\All Users
Community
  • 1
  • 1
Ganesh R.
  • 4,337
  • 3
  • 30
  • 46