, ( ), .
The enumeration failure SpecialFolderdoes not contain every known folder, so you need to use a little interaction, see MSDN . On this page we can find a complete list of known folders , what you are looking for is FOLDERID_Downloads , because the SHGetKnownFolderPath Function requires a GUID, which you must declare where something with this constant. Your code will look something like this:
static class ShellHelpers
{
public static string GetDownloadsFolder()
{
string path;
int result = SHGetKnownFolderPath(FOLDERID_Downloads, 0, IntPtr.Zero, out path);
if (result != NOERROR)
Marshal.ThrowExceptionForHR(result);
return path;
}
private static readonly Guid FOLDERID_Downloads = new Guid("374DE290-123F-4565-9164-39C4925E467B");
private static readonly int NOERROR = 0;
[DllImport("shell32.dll", CharSet=CharSet.Unicode)]
private static extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags, IntPtr hToken, out string pszPath);
}
Please note that you can use the P / Invoke signature that you prefer (some use StringBuilder and the other IntPtr).
source
share