Last active
December 3, 2024 11:41
-
-
Save godoway/2a957288683dc23ccde1eaf8654672bb to your computer and use it in GitHub Desktop.
get window download dirctory example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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