![]() ![]() This now allows us to replace out IntPtr path with out string path which makes the marshaller convert the string automatically, including freeing the memory 1. There are no A and W overloads, thus we also set ExactSpelling = true to prevent runtime searching for such. We specify CharSet = CharSet.Unicode since the returned string is always a Unicode PWSTR. But if you like, you can channel some more P/Invoke functionality to simplify the import and make its signature more ".NET-esque": Hans Passant's answer above about using SHGetKnownFolderPath is (as usual) absolutely correct. Or sometimes it's more convenient to fetch it using a string: var downloadPath = KnownFolders.GetPath(nameof(KnownFolders.Downloads)) Guid rfid, uint dwFlags, IntPtr hToken, out IntPtr ppszPath) Ĭan be called with: var downloadPath = KnownFolders.GetPath(KnownFolders.Downloads) Private static extern int SHGetKnownFolderPath( It may not be available on this system.") Throw new NotSupportedException("Unable to retrieve the path for known folder. String path = Marshal.PtrToStringUni(outPath) If (SHGetKnownFolderPath(knownFolderId, (uint)flags, new IntPtr(defaultUser ? -1 : 0), out var outPath) >= 0) KnownFolderFlags flags=KnownFolderFlags.DontVerify, bool defaultUser=false) Public static string GetPath(Guid knownFolderId, ? GetPath(knownFolderId, flags, defaultUser) ![]() Map.TryGetValue(knownFolder, out var knownFolderId) KnownFolderFlags flags = KnownFolderFlags.DontVerify, bool defaultUser = false) => Public static string GetPath(string knownFolder, By default, all major web browsers save files to this location, but it's. Once you open it, you'll see all the files you've saved to the 'Downloads' folder. Then either click 'Downloads' in the sidebar or double click the 'Downloads' folder in the main File Explorer window area. ![]() private static extern int SHGetKnownFolderPath( First, open File Explorer and click 'This PC' in the sidebar. The problem of your first answer is it would give you WRONG result if the default Downloads Dir has been changed to ! The proper way to do it covering all possibilities is using System ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |