PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Visual Studio 2008/CSShellKnownFolders/Program.cs

#
C# | 129 lines | 30 code | 19 blank | 80 comment | 0 complexity | abe135a438f5ad1d672f40c8cac99e3e MD5 | raw file
  1. /****************************** Module Header ******************************\
  2. * Module Name: Program.cs
  3. * Project: CSShellKnownFolders
  4. * Copyright (c) Microsoft Corporation.
  5. *
  6. * The Known Folder system provides a way to interact with certain
  7. * high-profile folders that are present by default in Microsoft Windows. It
  8. * also allows those same interactions with folders installed and registered
  9. * with the Known Folder system by applications. This sample demonstrates
  10. * those possible interactions in Visual C# as they are provided by the Known
  11. * Folder APIs.
  12. *
  13. * A. Enumerate and print all known folders.
  14. *
  15. * B. Print some built-in known folders like FOLDERID_ProgramFiles in two
  16. * different ways.
  17. *
  18. * C. Extend known folders with custom folders. (The feature is not
  19. * demonstrated in the current sample, because the APIs for extending known
  20. * folders with custom folders have not been exposed from Windows API Code
  21. * Pack for Microsoft .NET Framework.)
  22. *
  23. * This source is subject to the Microsoft Public License.
  24. * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
  25. * All other rights reserved.
  26. *
  27. * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
  28. * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
  30. \***************************************************************************/
  31. #region Using directives
  32. using System;
  33. using System.Collections.Generic;
  34. using System.Linq;
  35. using System.Text;
  36. using Microsoft.WindowsAPICodePack.Shell;
  37. #endregion
  38. class Program
  39. {
  40. static void Main(string[] args)
  41. {
  42. //
  43. // Enumerate and print all known folders.
  44. //
  45. Console.WriteLine("\nEnumerate all known folders");
  46. foreach (IKnownFolder kf in KnownFolders.All)
  47. {
  48. Console.WriteLine("{0}: {1}", kf.CanonicalName, kf.Path);
  49. }
  50. //
  51. // Print some default known folders in Windows.
  52. //
  53. // Program Files
  54. Console.WriteLine("FOLDERID_ProgramFiles: {0}",
  55. //KnownFolders.ProgramFiles.Path);
  56. // [-or-]
  57. Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
  58. // Known folders for per-computer program data.
  59. // The user would never want to browse here in Explorer, and settings
  60. // changed here should affect every user on the machine. The default
  61. // location is %systemdrive%\ProgramData, which is a hidden folder, on
  62. // an installation of Windows Vista. You'll want to create your
  63. // directory and set the ACLs you need at install time.
  64. Console.WriteLine("FOLDERID_ProgramData: {0}",
  65. //KnownFolders.ProgramData.Path);
  66. // [-or-]
  67. Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
  68. // The user would want to browse here in Explorer and double click to
  69. // open the file. The default location is %public%, which has
  70. // explicit links throughout Explorer, on an installation of Windows
  71. // Vista. You'll want to create your directory and set the ACLs you
  72. // need at install time.
  73. Console.WriteLine("FOLDERID_Public: {0}",
  74. //KnownFolders.Public.Path);
  75. // [-or-]
  76. Environment.GetEnvironmentVariable("public"));
  77. // Known folders for per-user program data.
  78. // The user would never want to browse here in Explorer, and settings
  79. // changed here should roam with the user. The default location is
  80. // %appdata%, which is a hidden folder, on an installation of Windows
  81. // Vista.
  82. Console.WriteLine("FOLDERID_RoamingAppData: {0}",
  83. //KnownFolders.RoamingAppData.Path);
  84. // [-or-]
  85. Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
  86. // The user would never want to browse here in Explorer, and settings
  87. // changed here should stay local to the computer. The default
  88. // location is %localappdata%, which is a hidden folder, on an
  89. // installation of Windows Vista.
  90. Console.WriteLine("FOLDERID_LocalAppData: {0}",
  91. //KnownFolders.LocalAppData.Path);
  92. // [-or-]
  93. Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
  94. // The user would want to browse here in Explorer and double click to
  95. // open the file. The default location is %userprofile%\documents,
  96. // which has explicit links throughout Explorer, on an installation
  97. // of Windows Vista.
  98. Console.WriteLine("FOLDERID_Documents: {0}",
  99. //KnownFolders.Documents.Path);
  100. // [-or-]
  101. Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
  102. //
  103. // Extend known folders with custom folders.
  104. //
  105. // TODO: The feature is not demonstrated in the current sample,
  106. // because the APIs for extending known folders with custom folders
  107. // have not been exposed from Windows API Code Pack for Microsoft
  108. // .NET Framework.
  109. }
  110. }