I\'m trying to locate the path for the AppData\\LocalLow
folder.
I have found an example which uses:
string folder = \"c:\\users\\\" + E
The Environment.SpecialFolder
enumeration maps to CSIDL, but there is no CSIDL
for the LocalLow
folder. So you have to use the KNOWNFOLDERID instead, with the SHGetKnownFolderPath
API:
void Main()
{
Guid localLowId = new Guid("A520A1A4-1780-4FF6-BD18-167343C5AF16");
GetKnownFolderPath(localLowId).Dump();
}
string GetKnownFolderPath(Guid knownFolderId)
{
IntPtr pszPath = IntPtr.Zero;
try
{
int hr = SHGetKnownFolderPath(knownFolderId, 0, IntPtr.Zero, out pszPath);
if (hr >= 0)
return Marshal.PtrToStringAuto(pszPath);
throw Marshal.GetExceptionForHR(hr);
}
finally
{
if (pszPath != IntPtr.Zero)
Marshal.FreeCoTaskMem(pszPath);
}
}
[DllImport("shell32.dll")]
static extern int SHGetKnownFolderPath( [MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags, IntPtr hToken, out IntPtr pszPath);