Subject | ProgramData on Vista |
---|---|
Author | Peter Morris |
Post date | 2008-02-21T15:51:31Z |
The problem lies in a combination of .NET and Vista. The problem is
that there is that Environment.GetFolderPath takes an enum
SpecialFolder which has just about every possible value you could want
*except* the one for shared application data, which is actually
CommonDocuments and not CommonApplicationData (which is read-only).
Just in case anyone out there experiences the same problem here is the
code I used to find the path of CommonDocuments at runtime, this is
where you should install your single-user GDB file.
Pete
public static class SpecialFolders
{
public static string GetFolderPath(SpecialFolderEx folder)
{
if (!Enum.IsDefined(typeof(SpecialFolderEx), folder))
throw new ArgumentException("Unknown folder: " + folder.ToString());
StringBuilder lpszPath = new StringBuilder(260);
SHGetFolderPath(IntPtr.Zero, (int)folder, IntPtr.Zero, 0, lpszPath);
string path = lpszPath.ToString();
new FileIOPermission(FileIOPermissionAccess.PathDiscovery,
path).Demand();
return path;
}
[DllImport("shfolder.dll", CharSet = CharSet.Auto)]
private static extern int SHGetFolderPath(IntPtr hwndOwner, int
nFolder, IntPtr hToken, int dwFlags, StringBuilder lpszPath);
}
public enum SpecialFolderEx
{
ApplicationData = 0x1a,
CommonApplicationData = 0x23,
CommonDocuments = 0x2e,
CommonProgramFiles = 0x2b,
Cookies = 0x21,
Desktop = 0,
DesktopDirectory = 0x10,
Favorites = 6,
History = 0x22,
InternetCache = 0x20,
LocalApplicationData = 0x1c,
MyComputer = 0x11,
MyDocuments = 5,
MyMusic = 13,
MyPictures = 0x27,
Personal = 5,
ProgramFiles = 0x26,
Programs = 2,
Recent = 8,
SendTo = 9,
StartMenu = 11,
Startup = 7,
System = 0x25,
Templates = 0x15,
Windows = 0x24
}
that there is that Environment.GetFolderPath takes an enum
SpecialFolder which has just about every possible value you could want
*except* the one for shared application data, which is actually
CommonDocuments and not CommonApplicationData (which is read-only).
Just in case anyone out there experiences the same problem here is the
code I used to find the path of CommonDocuments at runtime, this is
where you should install your single-user GDB file.
Pete
public static class SpecialFolders
{
public static string GetFolderPath(SpecialFolderEx folder)
{
if (!Enum.IsDefined(typeof(SpecialFolderEx), folder))
throw new ArgumentException("Unknown folder: " + folder.ToString());
StringBuilder lpszPath = new StringBuilder(260);
SHGetFolderPath(IntPtr.Zero, (int)folder, IntPtr.Zero, 0, lpszPath);
string path = lpszPath.ToString();
new FileIOPermission(FileIOPermissionAccess.PathDiscovery,
path).Demand();
return path;
}
[DllImport("shfolder.dll", CharSet = CharSet.Auto)]
private static extern int SHGetFolderPath(IntPtr hwndOwner, int
nFolder, IntPtr hToken, int dwFlags, StringBuilder lpszPath);
}
public enum SpecialFolderEx
{
ApplicationData = 0x1a,
CommonApplicationData = 0x23,
CommonDocuments = 0x2e,
CommonProgramFiles = 0x2b,
Cookies = 0x21,
Desktop = 0,
DesktopDirectory = 0x10,
Favorites = 6,
History = 0x22,
InternetCache = 0x20,
LocalApplicationData = 0x1c,
MyComputer = 0x11,
MyDocuments = 5,
MyMusic = 13,
MyPictures = 0x27,
Personal = 5,
ProgramFiles = 0x26,
Programs = 2,
Recent = 8,
SendTo = 9,
StartMenu = 11,
Startup = 7,
System = 0x25,
Templates = 0x15,
Windows = 0x24
}