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)
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.
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();
}
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With