added samples
[windows-sources.git] / sdk / samples / CrossTechnologySamples / VistaBridge / vistabridgelibrary / miscellaneous / knownfolders.cs
blob9b2ddf0591cb911d2b0321ebc98bb4ebad06845e
1 using System;
2 using System.Diagnostics;
3 using System.Runtime.InteropServices;
5 namespace Microsoft.SDK.Samples.VistaBridge.Library
7 public enum KnownFolderFindMode : int
9 ExactMatch = 0,
10 NearestParentMatch = ExactMatch + 1
13 public class KnownFolders
15 [Guid("8BE2D872-86AA-4d47-B776-32CCA40C7018"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
16 internal interface IKnownFolderManager
18 void FolderIdFromCsidl(int Csidl, [Out] out Guid knownFolderID);
19 void FolderIdToCsidl(
20 [In, MarshalAs(UnmanagedType.LPStruct)] Guid id,
21 [Out] out int Csidl);
23 void GetFolderIds();
24 void GetFolder(
25 [In, MarshalAs(UnmanagedType.LPStruct)] Guid id,
26 [Out, MarshalAs(UnmanagedType.Interface)] out KnownFolder.IKnownFolder knownFolder);
28 void GetFolderByName(string canonicalName, [Out, MarshalAs(UnmanagedType.Interface)] out KnownFolder.IKnownFolder knowFolder);
29 void RegisterFolder();
30 void UnregisterFolder();
31 void FindFolderFromPath([In, MarshalAs(UnmanagedType.LPWStr)] string path, [In] KnownFolderFindMode mode, [Out, MarshalAs(UnmanagedType.Interface)] out KnownFolder.IKnownFolder knownFolder);
32 void FindFolderFromIDList();
33 void Redirect();
36 [ComImport, Guid("4df0c730-df9d-4ae3-9153-aa6b82e9795a")]
37 internal class KnownFolderManager
41 static IKnownFolderManager _knownFolderManager = (IKnownFolderManager)new KnownFolderManager();
43 public static KnownFolder GetKnownFolder(int csidl)
45 Guid knownFolderID;
46 _knownFolderManager.FolderIdFromCsidl(csidl, out knownFolderID);
47 KnownFolder.IKnownFolder knowFolderInterface;
48 _knownFolderManager.GetFolder(knownFolderID, out knowFolderInterface);
49 return new KnownFolder(knowFolderInterface);
52 public static KnownFolder GetKnownFolder(Guid knownFolderID)
54 KnownFolder.IKnownFolder knowFolderInterface;
55 _knownFolderManager.GetFolder(knownFolderID, out knowFolderInterface);
56 return new KnownFolder(knowFolderInterface);
59 public static KnownFolder GetKnownFolder(string canonicalName)
61 KnownFolder.IKnownFolder knowFolderInterface;
62 _knownFolderManager.GetFolderByName(canonicalName, out knowFolderInterface);
63 return new KnownFolder(knowFolderInterface);
66 public static KnownFolder FindFolderFromPath(string path, KnownFolderFindMode mode)
68 KnownFolder.IKnownFolder knowFolderInterface;
69 _knownFolderManager.FindFolderFromPath(path, mode, out knowFolderInterface);
70 return new KnownFolder(knowFolderInterface);
73 public static int GetCsidl(Guid knownFolderID)
75 int csidl;
76 _knownFolderManager.FolderIdToCsidl(knownFolderID, out csidl);
77 return csidl;
80 private static string GetPath(Guid knownFolderID)
82 IntPtr pointerToPath = IntPtr.Zero;
83 string path;
84 try
86 KnownFolder.IKnownFolder knowFolderInterface;
87 _knownFolderManager.GetFolder(knownFolderID, out knowFolderInterface);
88 knowFolderInterface.GetPath(0, out pointerToPath);
89 path = Marshal.PtrToStringUni(pointerToPath);
91 finally
93 Marshal.FreeCoTaskMem(pointerToPath);
95 return path;
98 public static string Desktop
100 get { return GetPath(KnownFolderIdentifiers.Desktop); }
102 public static string Fonts
104 get { return GetPath(KnownFolderIdentifiers.Fonts); }
106 public static string Startup
108 get { return GetPath(KnownFolderIdentifiers.Startup); }
110 public static string Programs
112 get { return GetPath(KnownFolderIdentifiers.Programs); }
114 public static string StartMenu
116 get { return GetPath(KnownFolderIdentifiers.StartMenu); }
118 public static string Recent
120 get { return GetPath(KnownFolderIdentifiers.Recent); }
122 public static string SendTo
124 get { return GetPath(KnownFolderIdentifiers.SendTo); }
126 public static string Documents
128 get { return GetPath(KnownFolderIdentifiers.Documents); }
130 public static string Favorites
132 get { return GetPath(KnownFolderIdentifiers.Favorites); }
134 public static string NetHood
136 get { return GetPath(KnownFolderIdentifiers.NetHood); }
138 public static string PrintHood
140 get { return GetPath(KnownFolderIdentifiers.PrintHood); }
142 public static string Templates
144 get { return GetPath(KnownFolderIdentifiers.Templates); }
146 public static string CommonStartup
148 get { return GetPath(KnownFolderIdentifiers.CommonStartup); }
150 public static string CommonPrograms
152 get { return GetPath(KnownFolderIdentifiers.CommonPrograms); }
154 public static string CommonStartMenu
156 get { return GetPath(KnownFolderIdentifiers.CommonStartMenu); }
158 public static string PublicDesktop
160 get { return GetPath(KnownFolderIdentifiers.PublicDesktop); }
162 public static string ProgramData
164 get { return GetPath(KnownFolderIdentifiers.ProgramData); }
166 public static string CommonTemplates
168 get { return GetPath(KnownFolderIdentifiers.CommonTemplates); }
170 public static string PublicDocuments
172 get { return GetPath(KnownFolderIdentifiers.PublicDocuments); }
174 public static string RoamingAppData
176 get { return GetPath(KnownFolderIdentifiers.RoamingAppData); }
178 public static string LocalAppData
180 get { return GetPath(KnownFolderIdentifiers.LocalAppData); }
182 public static string LocalAppDataLow
184 get { return GetPath(KnownFolderIdentifiers.LocalAppDataLow); }
186 public static string InternetCache
188 get { return GetPath(KnownFolderIdentifiers.InternetCache); }
190 public static string Cookies
191 { get { return GetPath(KnownFolderIdentifiers.Cookies); } }
192 public static string History
193 { get { return GetPath(KnownFolderIdentifiers.History); } }
194 public static string System
195 { get { return GetPath(KnownFolderIdentifiers.System); } }
196 public static string SystemX86
197 { get { return GetPath(KnownFolderIdentifiers.SystemX86); } }
198 public static string Windows
199 { get { return GetPath(KnownFolderIdentifiers.Windows); } }
200 public static string Profile
201 { get { return GetPath(KnownFolderIdentifiers.Profile); } }
202 public static string Pictures
203 { get { return GetPath(KnownFolderIdentifiers.Pictures); } }
204 public static string ProgramFilesX86
205 { get { return GetPath(KnownFolderIdentifiers.ProgramFilesX86); } }
206 public static string ProgramFilesCommonX86
207 { get { return GetPath(KnownFolderIdentifiers.ProgramFilesCommonX86); } }
208 public static string ProgramFilesX64
209 { get { return GetPath(KnownFolderIdentifiers.ProgramFilesX64); } }
210 public static string ProgramFilesCommonX64
211 { get { return GetPath(KnownFolderIdentifiers.ProgramFilesCommonX64); } }
212 public static string ProgramFiles { get { return GetPath(KnownFolderIdentifiers.ProgramFiles); } }
213 public static string ProgramFilesCommon { get { return GetPath(KnownFolderIdentifiers.ProgramFilesCommon); } }
214 public static string AdminTools { get { return GetPath(KnownFolderIdentifiers.AdminTools); } }
215 public static string CommonAdminTools { get { return GetPath(KnownFolderIdentifiers.CommonAdminTools); } }
216 public static string Music { get { return GetPath(KnownFolderIdentifiers.Music); } }
217 public static string Videos { get { return GetPath(KnownFolderIdentifiers.Videos); } }
218 public static string PublicPictures { get { return GetPath(KnownFolderIdentifiers.PublicPictures); } }
219 public static string PublicMusic { get { return GetPath(KnownFolderIdentifiers.PublicMusic); } }
220 public static string PublicVideos { get { return GetPath(KnownFolderIdentifiers.PublicVideos); } }
221 public static string ResourceDir { get { return GetPath(KnownFolderIdentifiers.ResourceDir); } }
222 public static string LocalizedResourcesDir { get { return GetPath(KnownFolderIdentifiers.LocalizedResourcesDir); } }
223 public static string CommonOEMLinks { get { return GetPath(KnownFolderIdentifiers.CommonOEMLinks); } }
224 public static string CDBurning { get { return GetPath(KnownFolderIdentifiers.CDBurning); } }
225 public static string UserProfiles { get { return GetPath(KnownFolderIdentifiers.UserProfiles); } }
226 public static string Public { get { return GetPath(KnownFolderIdentifiers.Public); } }
227 public static string Downloads { get { return GetPath(KnownFolderIdentifiers.Downloads); } }
228 public static string PublicDownloads { get { return GetPath(KnownFolderIdentifiers.PublicDownloads); } }
229 public static string SavedSearches { get { return GetPath(KnownFolderIdentifiers.SavedSearches); } }
230 public static string QuickLaunch { get { return GetPath(KnownFolderIdentifiers.QuickLaunch); } }
231 public static string Contacts { get { return GetPath(KnownFolderIdentifiers.Contacts); } }
232 public static string SidebarParts { get { return GetPath(KnownFolderIdentifiers.SidebarParts); } }
233 public static string SidebarDefaultParts { get { return GetPath(KnownFolderIdentifiers.SidebarDefaultParts); } }
234 public static string PublicGameTasks { get { return GetPath(KnownFolderIdentifiers.PublicGameTasks); } }
235 public static string GameTasks { get { return GetPath(KnownFolderIdentifiers.GameTasks); } }
236 public static string SavedGames { get { return GetPath(KnownFolderIdentifiers.SavedGames); } }
237 public static string Links { get { return GetPath(KnownFolderIdentifiers.Links); } }
240 public class KnownFolderIdentifiers
242 public static Guid Computer = new Guid(0x0AC0837C, 0xBBF8, 0x452A, 0x85, 0x0D, 0x79, 0xD0, 0x8E, 0x66, 0x7C, 0xA7);
243 public static Guid Conflict = new Guid(0x4bfefb45, 0x347d, 0x4006, 0xa5, 0xbe, 0xac, 0x0c, 0xb0, 0x56, 0x71, 0x92);
244 public static Guid ControlPanel = new Guid(0x82A74AEB, 0xAEB4, 0x465C, 0xA0, 0x14, 0xD0, 0x97, 0xEE, 0x34, 0x6D, 0x63);
245 public static Guid Desktop = new Guid(0xB4BFCC3A, 0xDB2C, 0x424C, 0xB0, 0x29, 0x7F, 0xE9, 0x9A, 0x87, 0xC6, 0x41);
246 public static Guid Internet = new Guid(0x4D9F7874, 0x4E0C, 0x4904, 0x96, 0x7B, 0x40, 0xB0, 0xD2, 0x0C, 0x3E, 0x4B);
247 public static Guid Network = new Guid(0xD20BEEC4, 0x5CA8, 0x4905, 0xAE, 0x3B, 0xBF, 0x25, 0x1E, 0xA0, 0x9B, 0x53);
248 public static Guid Printers = new Guid(0x76FC4E2D, 0xD6AD, 0x4519, 0xA6, 0x63, 0x37, 0xBD, 0x56, 0x06, 0x81, 0x85);
249 public static Guid SyncManager = new Guid(0x43668BF8, 0xC14E, 0x49B2, 0x97, 0xC9, 0x74, 0x77, 0x84, 0xD7, 0x84, 0xB7);
250 public static Guid Connections = new Guid(0x6F0CD92B, 0x2E97, 0x45D1, 0x88, 0xFF, 0xB0, 0xD1, 0x86, 0xB8, 0xDE, 0xDD);
251 public static Guid SyncSetup = new Guid(0xf214138, 0xb1d3, 0x4a90, 0xbb, 0xa9, 0x27, 0xcb, 0xc0, 0xc5, 0x38, 0x9a);
252 public static Guid SyncResults = new Guid(0x289a9a43, 0xbe44, 0x4057, 0xa4, 0x1b, 0x58, 0x7a, 0x76, 0xd7, 0xe7, 0xf9);
253 public static Guid RecycleBin = new Guid(0xB7534046, 0x3ECB, 0x4C18, 0xBE, 0x4E, 0x64, 0xCD, 0x4C, 0xB7, 0xD6, 0xAC);
254 public static Guid Fonts = new Guid(0xFD228CB7, 0xAE11, 0x4AE3, 0x86, 0x4C, 0x16, 0xF3, 0x91, 0x0A, 0xB8, 0xFE);
255 public static Guid Startup = new Guid(0xB97D20BB, 0xF46A, 0x4C97, 0xBA, 0x10, 0x5E, 0x36, 0x08, 0x43, 0x08, 0x54);
256 public static Guid Programs = new Guid(0xA77F5D77, 0x2E2B, 0x44C3, 0xA6, 0xA2, 0xAB, 0xA6, 0x01, 0x05, 0x4A, 0x51);
257 public static Guid StartMenu = new Guid(0x625B53C3, 0xAB48, 0x4EC1, 0xBA, 0x1F, 0xA1, 0xEF, 0x41, 0x46, 0xFC, 0x19);
258 public static Guid Recent = new Guid(0xAE50C081, 0xEBD2, 0x438A, 0x86, 0x55, 0x8A, 0x09, 0x2E, 0x34, 0x98, 0x7A);
259 public static Guid SendTo = new Guid(0x8983036C, 0x27C0, 0x404B, 0x8F, 0x08, 0x10, 0x2D, 0x10, 0xDC, 0xFD, 0x74);
260 public static Guid Documents = new Guid(0xFDD39AD0, 0x238F, 0x46AF, 0xAD, 0xB4, 0x6C, 0x85, 0x48, 0x03, 0x69, 0xC7);
261 public static Guid Favorites = new Guid(0x1777F761, 0x68AD, 0x4D8A, 0x87, 0xBD, 0x30, 0xB7, 0x59, 0xFA, 0x33, 0xDD);
262 public static Guid NetHood = new Guid(0xC5ABBF53, 0xE17F, 0x4121, 0x89, 0x00, 0x86, 0x62, 0x6F, 0xC2, 0xC9, 0x73);
263 public static Guid PrintHood = new Guid(0x9274BD8D, 0xCFD1, 0x41C3, 0xB3, 0x5E, 0xB1, 0x3F, 0x55, 0xA7, 0x58, 0xF4);
264 public static Guid Templates = new Guid(0xA63293E8, 0x664E, 0x48DB, 0xA0, 0x79, 0xDF, 0x75, 0x9E, 0x05, 0x09, 0xF7);
265 public static Guid CommonStartup = new Guid(0x82A5EA35, 0xD9CD, 0x47C5, 0x96, 0x29, 0xE1, 0x5D, 0x2F, 0x71, 0x4E, 0x6E);
266 public static Guid CommonPrograms = new Guid(0x0139D44E, 0x6AFE, 0x49F2, 0x86, 0x90, 0x3D, 0xAF, 0xCA, 0xE6, 0xFF, 0xB8);
267 public static Guid CommonStartMenu = new Guid(0xA4115719, 0xD62E, 0x491D, 0xAA, 0x7C, 0xE7, 0x4B, 0x8B, 0xE3, 0xB0, 0x67);
268 public static Guid PublicDesktop = new Guid(0xC4AA340D, 0xF20F, 0x4863, 0xAF, 0xEF, 0xF8, 0x7E, 0xF2, 0xE6, 0xBA, 0x25);
269 public static Guid ProgramData = new Guid(0x62AB5D82, 0xFDC1, 0x4DC3, 0xA9, 0xDD, 0x07, 0x0D, 0x1D, 0x49, 0x5D, 0x97);
270 public static Guid CommonTemplates = new Guid(0xB94237E7, 0x57AC, 0x4347, 0x91, 0x51, 0xB0, 0x8C, 0x6C, 0x32, 0xD1, 0xF7);
271 public static Guid PublicDocuments = new Guid(0xED4824AF, 0xDCE4, 0x45A8, 0x81, 0xE2, 0xFC, 0x79, 0x65, 0x08, 0x36, 0x34);
272 public static Guid RoamingAppData = new Guid(0x3EB685DB, 0x65F9, 0x4CF6, 0xA0, 0x3A, 0xE3, 0xEF, 0x65, 0x72, 0x9F, 0x3D);
273 public static Guid LocalAppData = new Guid(0xF1B32785, 0x6FBA, 0x4FCF, 0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91);
274 public static Guid LocalAppDataLow = new Guid(0xA520A1A4, 0x1780, 0x4FF6, 0xBD, 0x18, 0x16, 0x73, 0x43, 0xC5, 0xAF, 0x16);
275 public static Guid InternetCache = new Guid(0x352481E8, 0x33BE, 0x4251, 0xBA, 0x85, 0x60, 0x07, 0xCA, 0xED, 0xCF, 0x9D);
276 public static Guid Cookies = new Guid(0x2B0F765D, 0xC0E9, 0x4171, 0x90, 0x8E, 0x08, 0xA6, 0x11, 0xB8, 0x4F, 0xF6);
277 public static Guid History = new Guid(0xD9DC8A3B, 0xB784, 0x432E, 0xA7, 0x81, 0x5A, 0x11, 0x30, 0xA7, 0x59, 0x63);
278 public static Guid System = new Guid(0x1AC14E77, 0x02E7, 0x4E5D, 0xB7, 0x44, 0x2E, 0xB1, 0xAE, 0x51, 0x98, 0xB7);
279 public static Guid SystemX86 = new Guid(0xD65231B0, 0xB2F1, 0x4857, 0xA4, 0xCE, 0xA8, 0xE7, 0xC6, 0xEA, 0x7D, 0x27);
280 public static Guid Windows = new Guid(0xF38BF404, 0x1D43, 0x42F2, 0x93, 0x05, 0x67, 0xDE, 0x0B, 0x28, 0xFC, 0x23);
281 public static Guid Profile = new Guid(0x5E6C858F, 0x0E22, 0x4760, 0x9A, 0xFE, 0xEA, 0x33, 0x17, 0xB6, 0x71, 0x73);
282 public static Guid Pictures = new Guid(0x33E28130, 0x4E1E, 0x4676, 0x83, 0x5A, 0x98, 0x39, 0x5C, 0x3B, 0xC3, 0xBB);
283 public static Guid ProgramFilesX86 = new Guid(0x7C5A40EF, 0xA0FB, 0x4BFC, 0x87, 0x4A, 0xC0, 0xF2, 0xE0, 0xB9, 0xFA, 0x8E);
284 public static Guid ProgramFilesCommonX86 = new Guid(0xDE974D24, 0xD9C6, 0x4D3E, 0xBF, 0x91, 0xF4, 0x45, 0x51, 0x20, 0xB9, 0x17);
285 public static Guid ProgramFilesX64 = new Guid(0x6d809377, 0x6af0, 0x444b, 0x89, 0x57, 0xa3, 0x77, 0x3f, 0x02, 0x20, 0x0e);
286 public static Guid ProgramFilesCommonX64 = new Guid(0x6365d5a7, 0xf0d, 0x45e5, 0x87, 0xf6, 0xd, 0xa5, 0x6b, 0x6a, 0x4f, 0x7d);
287 public static Guid ProgramFiles = new Guid(0x905e63b6, 0xc1bf, 0x494e, 0xb2, 0x9c, 0x65, 0xb7, 0x32, 0xd3, 0xd2, 0x1a);
288 public static Guid ProgramFilesCommon = new Guid(0xF7F1ED05, 0x9F6D, 0x47A2, 0xAA, 0xAE, 0x29, 0xD3, 0x17, 0xC6, 0xF0, 0x66);
289 public static Guid AdminTools = new Guid(0x724EF170, 0xA42D, 0x4FEF, 0x9F, 0x26, 0xB6, 0x0E, 0x84, 0x6F, 0xBA, 0x4F);
290 public static Guid CommonAdminTools = new Guid(0xD0384E7D, 0xBAC3, 0x4797, 0x8F, 0x14, 0xCB, 0xA2, 0x29, 0xB3, 0x92, 0xB5);
291 public static Guid Music = new Guid(0x4BD8D571, 0x6D19, 0x48D3, 0xBE, 0x97, 0x42, 0x22, 0x20, 0x08, 0x0E, 0x43);
292 public static Guid Videos = new Guid(0x18989B1D, 0x99B5, 0x455B, 0x84, 0x1C, 0xAB, 0x7C, 0x74, 0xE4, 0xDD, 0xFC);
293 public static Guid PublicPictures = new Guid(0xB6EBFB86, 0x6907, 0x413C, 0x9A, 0xF7, 0x4F, 0xC2, 0xAB, 0xF0, 0x7C, 0xC5);
294 public static Guid PublicMusic = new Guid(0x3214FAB5, 0x9757, 0x4298, 0xBB, 0x61, 0x92, 0xA9, 0xDE, 0xAA, 0x44, 0xFF);
295 public static Guid PublicVideos = new Guid(0x2400183A, 0x6185, 0x49FB, 0xA2, 0xD8, 0x4A, 0x39, 0x2A, 0x60, 0x2B, 0xA3);
296 public static Guid ResourceDir = new Guid(0x8AD10C31, 0x2ADB, 0x4296, 0xA8, 0xF7, 0xE4, 0x70, 0x12, 0x32, 0xC9, 0x72);
297 public static Guid LocalizedResourcesDir = new Guid(0x2A00375E, 0x224C, 0x49DE, 0xB8, 0xD1, 0x44, 0x0D, 0xF7, 0xEF, 0x3D, 0xDC);
298 public static Guid CommonOEMLinks = new Guid(0xC1BAE2D0, 0x10DF, 0x4334, 0xBE, 0xDD, 0x7A, 0xA2, 0x0B, 0x22, 0x7A, 0x9D);
299 public static Guid CDBurning = new Guid(0x9E52AB10, 0xF80D, 0x49DF, 0xAC, 0xB8, 0x43, 0x30, 0xF5, 0x68, 0x78, 0x55);
300 public static Guid UserProfiles = new Guid(0x0762D272, 0xC50A, 0x4BB0, 0xA3, 0x82, 0x69, 0x7D, 0xCD, 0x72, 0x9B, 0x80);
301 public static Guid Playlists = new Guid(0xDE92C1C7, 0x837F, 0x4F69, 0xA3, 0xBB, 0x86, 0xE6, 0x31, 0x20, 0x4A, 0x23);
302 public static Guid SamplePlaylists = new Guid(0x15CA69B3, 0x30EE, 0x49C1, 0xAC, 0xE1, 0x6B, 0x5E, 0xC3, 0x72, 0xAF, 0xB5);
303 public static Guid SampleMusic = new Guid(0xB250C668, 0xF57D, 0x4EE1, 0xA6, 0x3C, 0x29, 0x0E, 0xE7, 0xD1, 0xAA, 0x1F);
304 public static Guid SamplePictures = new Guid(0xC4900540, 0x2379, 0x4C75, 0x84, 0x4B, 0x64, 0xE6, 0xFA, 0xF8, 0x71, 0x6B);
305 public static Guid SampleVideos = new Guid(0x859EAD94, 0x2E85, 0x48AD, 0xA7, 0x1A, 0x09, 0x69, 0xCB, 0x56, 0xA6, 0xCD);
306 public static Guid PhotoAlbums = new Guid(0x69D2CF90, 0xFC33, 0x4FB7, 0x9A, 0x0C, 0xEB, 0xB0, 0xF0, 0xFC, 0xB4, 0x3C);
307 public static Guid Public = new Guid(0xDFDF76A2, 0xC82A, 0x4D63, 0x90, 0x6A, 0x56, 0x44, 0xAC, 0x45, 0x73, 0x85);
308 public static Guid ChangeRemovePrograms = new Guid(0xdf7266ac, 0x9274, 0x4867, 0x8d, 0x55, 0x3b, 0xd6, 0x61, 0xde, 0x87, 0x2d);
309 public static Guid AppUpdates = new Guid(0xa305ce99, 0xf527, 0x492b, 0x8b, 0x1a, 0x7e, 0x76, 0xfa, 0x98, 0xd6, 0xe4);
310 public static Guid AddNewPrograms = new Guid(0xde61d971, 0x5ebc, 0x4f02, 0xa3, 0xa9, 0x6c, 0x82, 0x89, 0x5e, 0x5c, 0x04);
311 public static Guid Downloads = new Guid(0x374de290, 0x123f, 0x4565, 0x91, 0x64, 0x39, 0xc4, 0x92, 0x5e, 0x46, 0x7b);
312 public static Guid PublicDownloads = new Guid(0x3d644c9b, 0x1fb8, 0x4f30, 0x9b, 0x45, 0xf6, 0x70, 0x23, 0x5f, 0x79, 0xc0);
313 public static Guid SavedSearches = new Guid(0x7d1d3a04, 0xdebb, 0x4115, 0x95, 0xcf, 0x2f, 0x29, 0xda, 0x29, 0x20, 0xda);
314 public static Guid QuickLaunch = new Guid(0x52a4f021, 0x7b75, 0x48a9, 0x9f, 0x6b, 0x4b, 0x87, 0xa2, 0x10, 0xbc, 0x8f);
315 public static Guid Contacts = new Guid(0x56784854, 0xc6cb, 0x462b, 0x81, 0x69, 0x88, 0xe3, 0x50, 0xac, 0xb8, 0x82);
316 public static Guid SidebarParts = new Guid(0xa75d362e, 0x50fc, 0x4fb7, 0xac, 0x2c, 0xa8, 0xbe, 0xaa, 0x31, 0x44, 0x93);
317 public static Guid SidebarDefaultParts = new Guid(0x7b396e54, 0x9ec5, 0x4300, 0xbe, 0xa, 0x24, 0x82, 0xeb, 0xae, 0x1a, 0x26);
318 public static Guid TreeProperties = new Guid(0x5b3749ad, 0xb49f, 0x49c1, 0x83, 0xeb, 0x15, 0x37, 0x0f, 0xbd, 0x48, 0x82);
319 public static Guid PublicGameTasks = new Guid(0xdebf2536, 0xe1a8, 0x4c59, 0xb6, 0xa2, 0x41, 0x45, 0x86, 0x47, 0x6a, 0xea);
320 public static Guid GameTasks = new Guid(0x54fae61, 0x4dd8, 0x4787, 0x80, 0xb6, 0x9, 0x2, 0x20, 0xc4, 0xb7, 0x0);
321 public static Guid SavedGames = new Guid(0x4c5c32ff, 0xbb9d, 0x43b0, 0xb5, 0xb4, 0x2d, 0x72, 0xe5, 0x4e, 0xaa, 0xa4);
322 public static Guid Games = new Guid(0xcac52c1a, 0xb53d, 0x4edc, 0x92, 0xd7, 0x6b, 0x2e, 0x8a, 0xc1, 0x94, 0x34);
323 public static Guid RecordedTV = new Guid(0xbd85e001, 0x112e, 0x431e, 0x98, 0x3b, 0x7b, 0x15, 0xac, 0x09, 0xff, 0xf1);
324 public static Guid SearchMapi = new Guid(0x98ec0e18, 0x2098, 0x4d44, 0x86, 0x44, 0x66, 0x97, 0x93, 0x15, 0xa2, 0x81);
325 public static Guid SearchCsc = new Guid(0xee32e446, 0x31ca, 0x4aba, 0x81, 0x4f, 0xa5, 0xeb, 0xd2, 0xfd, 0x6d, 0x5e);
326 public static Guid Links = new Guid(0xbfb9d5e0, 0xc6a9, 0x404c, 0xb2, 0xb2, 0xae, 0x6d, 0xb6, 0xaf, 0x49, 0x68);
327 public static Guid UsersFiles = new Guid(0xf3ce0f7c, 0x4901, 0x4acc, 0x86, 0x48, 0xd5, 0xd4, 0x4b, 0x04, 0xef, 0x8f);
328 public static Guid SearchHome = new Guid(0x190337d1, 0xb8ca, 0x4121, 0xa6, 0x39, 0x6d, 0x47, 0x2d, 0x16, 0x97, 0x2a);
329 public static Guid OriginalImages = new Guid(0x2C36C0AA, 0x5812, 0x4b87, 0xbf, 0xd0, 0x4c, 0xd0, 0xdf, 0xb1, 0x9b, 0x39);
332 public enum KnownFolderCategory
334 Virtual = 1,
335 Fixed = 2,
336 Common = 3,
337 PerUser = 4
340 public enum KnownFolderRetrievalOptions
342 Create = 0x00008000,
343 DontVerify = 0x00004000,
344 DontUnexpand = 0x00002000,
345 NoAlias = 0x00001000,
346 Init = 0x00000800,
347 DefaultPath = 0x00000400,
348 NotParentRelative = 0x00000200
351 public enum KnownFolderRedirectionCapabilities
353 AllowAll = 0xff,
354 Redirectable = 0x1,
355 DenyAll = 0xfff00,
356 DenyPolicyRedirected = 0x100,
357 DenyPolicy = 0x200,
358 DenyPermissions = 0x400
361 public enum KnownFolderDefinitionFlags
363 LocalRedirectOnly = 0x2,
364 Roamable = 0x4,
365 Precreate = 0x8
368 public struct KnownFolderDefinition
370 public KnownFolderCategory Category;
371 public string Name;
372 public string Description;
373 public Guid ParentID;
374 public string RelativePath;
375 public string ParsingName;
376 public string Tooltip;
377 public string LocalizedName;
378 public string Icon;
379 public string Security;
380 public UInt32 Attributes;
381 public KnownFolderDefinitionFlags DefinitionFlags;
382 public Guid FolderTypeID;
385 public class KnownFolder
387 [ComImport, Guid("3AA7AF7E-9B36-420c-A8E3-F77D4674A488"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
388 internal interface IKnownFolder
390 void GetId([Out] out Guid Id);
391 void GetCategory([Out] out KnownFolderCategory category);
392 void GetShellItem(
393 KnownFolderRetrievalOptions retrievalOptions,
394 [MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
395 [Out, MarshalAs(UnmanagedType.IUnknown)] out object shellItem);
396 void GetPath(
397 KnownFolderRetrievalOptions retrievalOptions,
398 [Out] out IntPtr path);
400 void SetPath(KnownFolderRetrievalOptions retrievalOptions, string path);
401 void GetIDList(KnownFolderRetrievalOptions retrievalOptions,
402 [Out] out IntPtr itemIdentifierListPointer);
403 void GetFolderType([Out, MarshalAs(UnmanagedType.LPStruct)] out Guid folderTypeID);
404 void GetRedirectionCapabilities([Out] out KnownFolderRedirectionCapabilities redirectionCapabilities);
405 void GetFolderDefinition([Out, MarshalAs(UnmanagedType.Struct)] out InternalKnownFolderDefinition definition);
408 IKnownFolder _knownFolder = null;
410 internal KnownFolder(IKnownFolder knownFolder)
412 _knownFolder = knownFolder;
415 public string Path
417 get { return GetPath(0); }
418 set { SetPath(value, 0); }
421 public string GetPath(KnownFolderRetrievalOptions options)
423 IntPtr pointerToPath = IntPtr.Zero;
424 string path;
427 _knownFolder.GetPath(options, out pointerToPath);
428 path = Marshal.PtrToStringUni(pointerToPath);
430 finally
432 Marshal.FreeCoTaskMem(pointerToPath);
434 return path;
437 public void SetPath(string path, KnownFolderRetrievalOptions options)
439 _knownFolder.SetPath(options, path);
442 public Guid Id
446 Guid id;
447 _knownFolder.GetId(out id);
448 return id;
452 public Guid FolderType
456 Guid type;
457 _knownFolder.GetFolderType(out type);
458 return type;
461 public KnownFolderCategory Category
465 KnownFolderCategory category;
466 _knownFolder.GetCategory(out category);
467 return category;
470 public KnownFolderRedirectionCapabilities RedirectionCapabilities
474 KnownFolderRedirectionCapabilities redirectionCapabilities;
475 _knownFolder.GetRedirectionCapabilities(out redirectionCapabilities);
476 return redirectionCapabilities;
480 internal struct InternalKnownFolderDefinition
482 internal KnownFolderCategory Category;
483 internal IntPtr pszName;
484 internal IntPtr pszDescription;
485 internal Guid ParentID;
486 internal IntPtr pszRelativePath;
487 internal IntPtr pszParsingName;
488 internal IntPtr pszTooltip;
489 internal IntPtr pszLocalizedName;
490 internal IntPtr pszIcon;
491 internal IntPtr pszSecurity;
492 internal UInt32 dwAttributes;
493 internal KnownFolderDefinitionFlags DefinitionFlags;
494 internal Guid FolderTypeID;
497 // This is not a small operation so it should be a method.
498 public KnownFolderDefinition GetDefinition()
500 InternalKnownFolderDefinition internalDefinition;
501 KnownFolderDefinition definition = new KnownFolderDefinition();
502 _knownFolder.GetFolderDefinition(out internalDefinition);
505 definition.Category = internalDefinition.Category;
506 definition.Name = Marshal.PtrToStringUni(
507 internalDefinition.pszName);
509 definition.Description = Marshal.PtrToStringUni(
510 internalDefinition.pszDescription);
512 definition.ParentID = internalDefinition.ParentID;
513 definition.ParsingName = Marshal.PtrToStringUni(
514 internalDefinition.pszParsingName);
516 definition.Tooltip = Marshal.PtrToStringUni(
517 internalDefinition.pszTooltip);
518 definition.LocalizedName = Marshal.PtrToStringUni(internalDefinition.pszLocalizedName);
519 definition.Icon = Marshal.PtrToStringUni(
520 internalDefinition.pszIcon);
521 definition.Security = Marshal.PtrToStringUni(
522 internalDefinition.pszSecurity);
523 definition.Attributes = internalDefinition.dwAttributes;
524 definition.DefinitionFlags = internalDefinition.DefinitionFlags;
525 definition.FolderTypeID = internalDefinition.FolderTypeID;
527 finally
529 Marshal.FreeCoTaskMem(internalDefinition.pszName);
530 Marshal.FreeCoTaskMem(internalDefinition.pszDescription);
531 Marshal.FreeCoTaskMem(internalDefinition.pszRelativePath);
532 Marshal.FreeCoTaskMem(internalDefinition.pszParsingName);
533 Marshal.FreeCoTaskMem(internalDefinition.pszTooltip);
534 Marshal.FreeCoTaskMem(internalDefinition.pszLocalizedName);
535 Marshal.FreeCoTaskMem(internalDefinition.pszIcon);
536 Marshal.FreeCoTaskMem(internalDefinition.pszSecurity);
538 return definition;