PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms 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
 32#region Using directives
 33using System;
 34using System.Collections.Generic;
 35using System.Linq;
 36using System.Text;
 37using Microsoft.WindowsAPICodePack.Shell;
 38#endregion
 39
 40
 41class Program
 42{
 43    static void Main(string[] args)
 44    {
 45        // 
 46        // Enumerate and print all known folders.
 47        // 
 48
 49        Console.WriteLine("\nEnumerate all known folders");
 50        foreach (IKnownFolder kf in KnownFolders.All)
 51        {
 52            Console.WriteLine("{0}: {1}", kf.CanonicalName, kf.Path);
 53        }
 54
 55
 56        // 
 57        // Print some default known folders in Windows.
 58        // 
 59
 60        // Program Files
 61        Console.WriteLine("FOLDERID_ProgramFiles: {0}", 
 62            //KnownFolders.ProgramFiles.Path);
 63            // [-or-]
 64            Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
 65        
 66
 67        // Known folders for per-computer program data.
 68
 69        // The user would never want to browse here in Explorer, and settings 
 70        // changed here should affect every user on the machine. The default 
 71        // location is %systemdrive%\ProgramData, which is a hidden folder, on 
 72        // an installation of Windows Vista. You'll want to create your 
 73        // directory and set the ACLs you need at install time.
 74        Console.WriteLine("FOLDERID_ProgramData: {0}",
 75            //KnownFolders.ProgramData.Path);
 76            // [-or-]
 77            Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
 78
 79        // The user would want to browse here in Explorer and double click to 
 80        // open the file. The default location is %public%, which has 
 81        // explicit links throughout Explorer, on an installation of Windows 
 82        // Vista. You'll want to create your directory and set the ACLs you 
 83        // need at install time.
 84        Console.WriteLine("FOLDERID_Public: {0}",
 85            //KnownFolders.Public.Path);
 86            // [-or-]
 87            Environment.GetEnvironmentVariable("public"));
 88
 89
 90        // Known folders for per-user program data.
 91
 92        // The user would never want to browse here in Explorer, and settings 
 93        // changed here should roam with the user. The default location is 
 94        // %appdata%, which is a hidden folder, on an installation of Windows 
 95        // Vista.
 96        Console.WriteLine("FOLDERID_RoamingAppData: {0}",
 97            //KnownFolders.RoamingAppData.Path);
 98            // [-or-]
 99            Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
100
101        // The user would never want to browse here in Explorer, and settings 
102        // changed here should stay local to the computer. The default 
103        // location is %localappdata%, which is a hidden folder, on an 
104        // installation of Windows Vista.
105        Console.WriteLine("FOLDERID_LocalAppData: {0}",
106            //KnownFolders.LocalAppData.Path);
107            // [-or-]
108            Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
109
110        // The user would want to browse here in Explorer and double click to 
111        // open the file. The default location is %userprofile%\documents, 
112        // which has explicit links throughout Explorer, on an installation 
113        // of Windows Vista.
114        Console.WriteLine("FOLDERID_Documents: {0}",
115            //KnownFolders.Documents.Path);
116            // [-or-]
117            Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
118
119
120        // 
121        // Extend known folders with custom folders.
122        // 
123
124        // TODO: The feature is not demonstrated in the current sample, 
125        // because the APIs for extending known folders with custom folders 
126        // have not been exposed from Windows API Code Pack for Microsoft 
127        // .NET Framework.
128    }
129}