Skip to content

Instantly share code, notes, and snippets.

@godoway
Last active December 3, 2024 11:41
Show Gist options
  • Select an option

  • Save godoway/2a957288683dc23ccde1eaf8654672bb to your computer and use it in GitHub Desktop.

Select an option

Save godoway/2a957288683dc23ccde1eaf8654672bb to your computer and use it in GitHub Desktop.
get window download dirctory example
using System.Runtime.InteropServices;
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
static extern int SHGetKnownFolderPath(ref Guid rfid, uint dwFlags, IntPtr hToken, out IntPtr ppszPath);
Guid downloadsFolder = new Guid("374DE290-123F-4565-9164-39C4925E467B");
int hr = SHGetKnownFolderPath(ref downloadsFolder, 0, IntPtr.Zero, out var pPath);
if (hr == 0) // S_OK
{
string? path = Marshal.PtrToStringUni(pPath);
Marshal.FreeCoTaskMem(pPath);
Console.WriteLine($"下载文件夹路径: {path}");
}
else
{
Console.WriteLine("无法获取下载文件夹路径。错误代码: " + hr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment