GPAL - Generally Positive Automation Library v1.0
GPAL The Fluent Automation LIbrary
Loading...
Searching...
No Matches
KnownFolders.cs
1// =============================================================================
2// GPAL - Generally Positive Automation Library
3// Copyright © 2026 Software Decisions, Inc. All rights reserved.
4//
5// This file is part of GPAL.
6// Licensed under the Business Source License 1.1
7//
8// Primary development, architecture, and vision by Michael B. Vederman,
9// CEO of Software Decisions, Inc., Texas.
10//
11// Internal development maintained privately.
12// Public releases appear on GitHub: https://github.com/SoftwareDecisionsInc/GPAL.
13//
14// See LICENSE for full terms, including Additional Use Grant.
15// =============================================================================
16
17using System;
18using System.Runtime.InteropServices;
19
20// https://www.codeproject.com/Articles/878605/Getting-all-Special-Folders-in-NET
21namespace GenerallyPositive
22{
26 internal static class KnownFolders
27 {
28 // ---- FIELDS -------------------------------------------------------------------------------------------------
29
30 #region private static string[] _knownFolderGuids = new string[]
31 private static string[] _knownFolderGuids = new string[]
32 {
33 "{008CA0B1-55B4-4C56-B8A8-4DE4B299D3BE}", // AccountPictures
34 "{724EF170-A42D-4FEF-9F26-B60E846FBA4F}", // AdminTools
35 "{A3918781-E5F2-4890-B3D9-A7E54332328C}", // ApplicationShortcuts
36 "{AB5FB87B-7CE2-4F83-915D-550846C9537B}", // CameraRool
37 "{9E52AB10-F80D-49DF-ACB8-4330F5687855}", // CDBurning
38 "{D0384E7D-BAC3-4797-8F14-CBA229B392B5}", // CommonAdminTools
39 "{C1BAE2D0-10DF-4334-BEDD-7AA20B227A9D}", // CommonOemLinks
40 "{0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8}", // CommonPrograms
41 "{A4115719-D62E-491D-AA7C-E74B8BE3B067}", // CommonStartMenu
42 "{82A5EA35-D9CD-47C5-9629-E15D2F714E6E}", // CommonStartup
43 "{B94237E7-57AC-4347-9151-B08C6C32D1F7}", // CommonTemplates
44 "{56784854-C6CB-462B-8169-88E350ACB882}", // Contacts
45 "{2B0F765D-C0E9-4171-908E-08A611B84FF6}", // Cookies
46 "{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}", // Desktop
47 "{5CE4A5E9-E4EB-479D-B89F-130C02886155}", // DeviceMetadataStore
48 "{FDD39AD0-238F-46AF-ADB4-6C85480369C7}", // Documents
49 "{7B0DB17D-9CD2-4A93-9733-46CC89022E7C}", // DocumentsLibrary
50 "{374DE290-123F-4565-9164-39C4925E467B}", // Downloads
51 "{1777F761-68AD-4D8A-87BD-30B759FA33DD}", // Favorites
52 "{FD228CB7-AE11-4AE3-864C-16F3910AB8FE}", // Fonts
53 "{054FAE61-4DD8-4787-80B6-090220C4B700}", // GameTasks
54 "{D9DC8A3B-B784-432E-A781-5A1130A75963}", // History
55 "{BCB5256F-79F6-4CEE-B725-DC34E402FD46}", // ImplicitAppShortcuts
56 "{352481E8-33BE-4251-BA85-6007CAEDCF9D}", // InternetCache
57 "{1B3EA5DC-B587-4786-B4EF-BD1DC332AEAE}", // Libraries
58 "{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}", // Links
59 "{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}", // LocalAppData
60 "{A520A1A4-1780-4FF6-BD18-167343C5AF16}", // LocalAppDataLow
61 "{2A00375E-224C-49DE-B8D1-440DF7EF3DDC}", // LocalizedResourcesDir
62 "{4BD8D571-6D19-48D3-BE97-422220080E43}", // Music
63 "{2112AB0A-C86A-4FFE-A368-0DE96E47012E}", // MusicLibrary
64 "{C5ABBF53-E17F-4121-8900-86626FC2C973}", // NetHood
65 "{2C36C0AA-5812-4B87-BFD0-4CD0DFB19B39}", // OriginalImages
66 "{69D2CF90-FC33-4FB7-9A0C-EBB0F0FCB43C}", // PhotoAlbums
67 "{A990AE9F-A03B-4E80-94BC-9912D7504104}", // PicturesLibrary
68 "{33E28130-4E1E-4676-835A-98395C3BC3BB}", // Pictures
69 "{DE92C1C7-837F-4F69-A3BB-86E631204A23}", // Playlists
70 "{9274BD8D-CFD1-41C3-B35E-B13F55A758F4}", // PrintHood
71 "{5E6C858F-0E22-4760-9AFE-EA3317B67173}", // Profile
72 "{62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}", // ProgramData
73 "{905E63B6-C1BF-494E-B29C-65B732D3D21A}", // ProgramFiles
74 "{6D809377-6AF0-444B-8957-A3773F02200E}", // ProgramFilesX64
75 "{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}", // ProgramFilesX86
76 "{F7F1ED05-9F6D-47A2-AAAE-29D317C6F066}", // ProgramFilesCommon
77 "{6365D5A7-0F0D-45E5-87F6-0DA56B6A4F7D}", // ProgramFilesCommonX64
78 "{DE974D24-D9C6-4D3E-BF91-F4455120B917}", // ProgramFilesCommonX86
79 "{A77F5D77-2E2B-44C3-A6A2-ABA601054A51}", // Programs
80 "{DFDF76A2-C82A-4D63-906A-5644AC457385}", // Public
81 "{C4AA340D-F20F-4863-AFEF-F87EF2E6BA25}", // PublicDesktop
82 "{ED4824AF-DCE4-45A8-81E2-FC7965083634}", // PublicDocuments
83 "{3D644C9B-1FB8-4F30-9B45-F670235F79C0}", // PublicDownloads
84 "{DEBF2536-E1A8-4C59-B6A2-414586476AEA}", // PublicGameTasks
85 "{48DAF80B-E6CF-4F4E-B800-0E69D84EE384}", // PublicLibraries
86 "{3214FAB5-9757-4298-BB61-92A9DEAA44FF}", // PublicMusic
87 "{B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5}", // PublicPictures
88 "{E555AB60-153B-4D17-9F04-A5FE99FC15EC}", // PublicRingtones
89 "{0482AF6C-08F1-4C34-8C90-E17EC98B1E17}", // PublicUserTiles
90 "{2400183A-6185-49FB-A2D8-4A392A602BA3}", // PublicVideos
91 "{52A4F021-7B75-48A9-9F6B-4B87A210BC8F}", // QuickLaunch
92 "{AE50C081-EBD2-438A-8655-8A092E34987A}", // Recent
93 "{1A6FDBA2-F42D-4358-A798-B74D745926C5}", // RecordedTVLibrary
94 "{8AD10C31-2ADB-4296-A8F7-E4701232C972}", // ResourceDir
95 "{C870044B-F49E-4126-A9C3-B52A1FF411E8}", // Ringtones
96 "{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}", // RoamingAppData
97 "{AAA8D5A5-F1D6-4259-BAA8-78E7EF60835E}", // RoamedTileImages
98 "{00BCFC5A-ED94-4E48-96A1-3F6217F21990}", // RoamingTiles
99 "{B250C668-F57D-4EE1-A63C-290EE7D1AA1F}", // SampleMusic
100 "{C4900540-2379-4C75-844B-64E6FAF8716B}", // SamplePictures
101 "{15CA69B3-30EE-49C1-ACE1-6B5EC372AFB5}", // SamplePlaylists
102 "{859EAD94-2E85-48AD-A71A-0969CB56A6CD}", // SampleVideos
103 "{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}", // SavedGames
104 "{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}", // SavedSearches
105 "{B7BEDE81-DF94-4682-A7D8-57A52620B86F}", // Screenshots
106 "{0D4C3DB6-03A3-462F-A0E6-08924C41B5D4}", // SearchHistory
107 "{7E636BFE-DFA9-4D5E-B456-D7B39851D8A9}", // SearchTemplates
108 "{8983036C-27C0-404B-8F08-102D10DCFD74}", // SendTo
109 "{7B396E54-9EC5-4300-BE0A-2482EBAE1A26}", // SidebearDefaultParts
110 "{A75D362E-50FC-4FB7-AC2C-A8BEAA314493}", // SidebarParts
111 "{A52BBA46-E9E1-435F-B3D9-28DAA648C0F6}", // SkyDrive
112 "{767E6811-49CB-4273-87C2-20F355E1085B}", // SkyDriveCameraRoll
113 "{24D89E24-2F19-4534-9DDE-6A6671FBB8FE}", // SkyDriveDocuments
114 "{339719B5-8C47-4894-94C2-D8F77ADD44A6}", // SkyDrivePictures
115 "{625B53C3-AB48-4EC1-BA1F-A1EF4146FC19}", // StartMenu
116 "{B97D20BB-F46A-4C97-BA10-5E3608430854}", // Startup
117 "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}", // System
118 "{D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27}", // SystemX86
119 "{A63293E8-664E-48DB-A079-DF759E0509F7}", // Templates
120 "{9E3995AB-1F9C-4F13-B827-48B24B6C7174}", // UserPinned
121 "{0762D272-C50A-4BB0-A382-697DCD729B80}", // UserProfiles
122 "{5CD7AEE2-2219-4A67-B85D-6C9CE15660CB}", // UserProgramFiles
123 "{BCBD3057-CA5C-4622-B42D-BC56DB0AE516}", // UserProgramFilesCommon
124 "{18989B1D-99B5-455B-841C-AB7C74E4DDFC}", // Videos
125 "{491E922F-5643-4AF4-A7EB-4E7A138D8174}", // VideosLibrary
126 "{F38BF404-1D43-42F2-9305-67DE0B28FC23}" // Windows
127 };
128 #endregion
129
130 // ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
131
139 internal static string GetPath(KnownFolder knownFolder)
140 {
141 return GetPath(knownFolder, false);
142 }
143
153 internal static string GetPath(KnownFolder knownFolder, bool defaultUser)
154 {
155 return GetPath(knownFolder, KnownFolderFlags.DontVerify, defaultUser);
156 }
157
164 internal static string GetDefaultPath(KnownFolder knownFolder)
165 {
166 return GetDefaultPath(knownFolder, false);
167 }
168
177 internal static string GetDefaultPath(KnownFolder knownFolder, bool defaultUser)
178 {
179 return GetPath(knownFolder, KnownFolderFlags.DefaultPath | KnownFolderFlags.DontVerify, defaultUser);
180 }
181
187 internal static void Initialize(KnownFolder knownFolder)
188 {
189 Initialize(knownFolder, false);
190 }
191
199 internal static void Initialize(KnownFolder knownFolder, bool defaultUser)
200 {
201 GetPath(knownFolder, KnownFolderFlags.Create | KnownFolderFlags.Init, defaultUser);
202 }
203
204 // ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
205
206 private static string GetPath(KnownFolder knownFolder, KnownFolderFlags flags, bool defaultUser)
207 {
208 int result = SHGetKnownFolderPath(new Guid(_knownFolderGuids[(int)knownFolder]), (uint)flags,
209 new IntPtr(defaultUser ? -1 : 0), out IntPtr outPath);
210 if (result >= 0)
211 {
212 string path = Marshal.PtrToStringUni(outPath);
213 Marshal.FreeCoTaskMem(outPath);
214 return path;
215 }
216 else
217 {
218 throw new ExternalException(
219 "Unable to retrieve the known folder path. It may not be available on this system.", result);
220 }
221 }
222
236 [DllImport("Shell32.dll")]
237 private static extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)]Guid rfid, uint dwFlags,
238 IntPtr hToken, out IntPtr ppszPath);
239
240 // ---- CLASSES, STRUCTS & ENUMS -------------------------------------------------------------------------------
241
242 [Flags]
243 private enum KnownFolderFlags : uint
244 {
245 SimpleIDList = 0x00000100,
246 NotParentRelative = 0x00000200,
247 DefaultPath = 0x00000400,
248 Init = 0x00000800,
249 NoAlias = 0x00001000,
250 DontUnexpand = 0x00002000,
251 DontVerify = 0x00004000,
252 Create = 0x00008000,
253 NoAppcontainerRedirection = 0x00010000,
254 AliasOnly = 0x80000000
255 }
256 }
257
262 internal enum KnownFolder
263 {
268 AccountPictures,
269
274 AdminTools,
275
280 ApplicationShortcuts,
281
286 CameraRoll,
287
292 CDBurning,
293
298 CommonAdminTools,
299
304 CommonOemLinks,
305
310 CommonPrograms,
311
316 CommonStartMenu,
317
322 CommonStartup,
323
328 CommonTemplates,
329
334 Contacts,
335
340 Cookies,
341
346 Desktop,
347
352 DeviceMetadataStore,
353
358 Documents,
359
364 DocumentsLibrary,
365
370 Downloads,
371
376 Favorites,
377
382 Fonts,
383
388 GameTasks,
389
394 History,
395
400 ImplicitAppShortcuts,
401
406 InternetCache,
407
412 Libraries,
413
418 Links,
419
424 LocalAppData,
425
430 LocalAppDataLow,
431
436 LocalizedResourcesDir,
437
442 Music,
443
448 MusicLibrary,
449
454 NetHood,
455
460 OriginalImages,
461
466 PhotoAlbums,
467
472 PicturesLibrary,
473
478 Pictures,
479
484 Playlists,
485
490 PrintHood,
491
496 Profile,
497
503 ProgramData,
504
513 ProgramFiles,
514
520 ProgramFilesX64,
521
528 ProgramFilesX86,
529
538 ProgramFilesCommon,
539
545 ProgramFilesCommonX64,
546
553 ProgramFilesCommonX86,
554
559 Programs,
560
565 Public,
566
571 PublicDesktop,
572
577 PublicDocuments,
578
583 PublicDownloads,
584
589 PublicGameTasks,
590
595 PublicLibraries,
596
601 PublicMusic,
602
607 PublicPictures,
608
613 PublicRingtones,
614
619 PublicUserTiles,
620
625 PublicVideos,
626
631 QuickLaunch,
632
637 Recent,
638
643 RecordedTVLibrary,
644
649 ResourceDir,
650
655 Ringtones,
656
661 RoamingAppData,
662
667 RoamedTileImages,
668
673 RoamingTiles,
674
679 SampleMusic,
680
685 SamplePictures,
686
691 SamplePlaylists,
692
697 SampleVideos,
698
703 SavedGames,
704
709 SavedSearches,
710
715 Screenshots,
716
721 SearchHistory,
722
727 SearchTemplates,
728
733 SendTo,
734
739 SidebarDefaultParts,
740
745 SidebarParts,
746
751 SkyDrive,
752
757 SkyDriveCameraRoll,
758
763 SkyDriveDocuments,
764
769 SkyDrivePictures,
770
775 StartMenu,
776
781 Startup,
782
789 System,
790
797 SystemX86,
798
803 Templates,
804
809 UserPinned,
810
815 UserProfiles,
816
821 UserProgramFiles,
822
827 UserProgramFilesCommon,
828
833 Videos,
834
839 VideosLibrary,
840
845 Windows
846 }
847}
848