为什么Visual Studio只暴露了Environment.SpecialFolder枚举的一部分?

时间:2014-03-21 11:18:25

标签: .net visual-studio

<。> .Net文档显示Environment.SpecialFolder枚举是广泛的,并适用于所有版本的框架,包括4.0。 但是当我尝试在Visual Studio 2010 Professional中使用它时,我发现intellisense无法识别其CommonDocuments成员。我使用上下文菜单&#34;转到定义&#34;,于是它打开了一个名为&#34; Environment [from metadata]&#34;的新选项卡。它显示了SpecialFolder枚举如下:

    // Summary:
    //     Specifies enumerated constants used to retrieve directory paths to system
    //     special folders.
    [ComVisible(true)]
    public enum SpecialFolder
    {
        // Summary:
        //     The logical Desktop rather than the physical file system location.
        Desktop = 0,
        //
        // Summary:
        //     The directory that contains the user's program groups.
        Programs = 2,
        //
        // Summary:
        //     The directory that serves as a common repository for documents.
        Personal = 5,
        //
        // Summary:
        //     The "My Documents" folder.
        MyDocuments = 5,
        //
        // Summary:
        //     The directory that serves as a common repository for the user's favorite
        //     items.
        Favorites = 6,
        //
        // Summary:
        //     The directory that corresponds to the user's Startup program group.
        Startup = 7,
        //
        // Summary:
        //     The directory that contains the user's most recently used documents.
        Recent = 8,
        //
        // Summary:
        //     The directory that contains the Send To menu items.
        SendTo = 9,
        //
        // Summary:
        //     The directory that contains the Start menu items.
        StartMenu = 11,
        //
        // Summary:
        //     The "My Music" folder.
        MyMusic = 13,
        //
        // Summary:
        //     The directory used to physically store file objects on the desktop.
        DesktopDirectory = 16,
        //
        // Summary:
        //     The "My Computer" folder.
        MyComputer = 17,
        //
        // Summary:
        //     The directory that serves as a common repository for document templates.
        Templates = 21,
        //
        // Summary:
        //     The directory that serves as a common repository for application-specific
        //     data for the current roaming user.
        ApplicationData = 26,
        //
        // Summary:
        //     The directory that serves as a common repository for application-specific
        //     data that is used by the current, non-roaming user.
        LocalApplicationData = 28,
        //
        // Summary:
        //     The directory that serves as a common repository for temporary Internet files.
        InternetCache = 32,
        //
        // Summary:
        //     The directory that serves as a common repository for Internet cookies.
        Cookies = 33,
        //
        // Summary:
        //     The directory that serves as a common repository for Internet history items.
        History = 34,
        //
        // Summary:
        //     The directory that serves as a common repository for application-specific
        //     data that is used by all users.
        CommonApplicationData = 35,
        //
        // Summary:
        //     The System directory.
        System = 37,
        //
        // Summary:
        //     The program files directory.
        ProgramFiles = 38,
        //
        // Summary:
        //     The "My Pictures" folder.
        MyPictures = 39,
        //
        // Summary:
        //     The directory for components that are shared across applications.
        CommonProgramFiles = 43,
    }

正如您所看到的,它会跳过值,因为它通过其成员列表工作,并在CommonProgramFiles处停止。该文档显示了此枚举的47个成员,而Visual Studio显示它只包含23个成员。

任何人都可以解释这种差异以及我需要做些什么来纠正它吗?

迈克尔

2 个答案:

答案 0 :(得分:2)

  

它的2.0

这是一个仍然支持Windows 98和2000的.NET版本。没有常见文件夹的古老操作系统。一般来说,.NET中存在一个问题,它试图与操作系统版本无关,但这确实很难利用更新的操作系统功能。

枚举在.NET 4.0中进行了扩展,可能是因为它放弃了对Windows 2000的支持。

请将此作为一个不明确的暗示,以.NET 2.0为目标不再有任何意义。您发现实际需要它的客户的可能性微乎其微。当他遇到Windows 98或2000特定问题时,你会非常怀疑他是否支持他。

答案 1 :(得分:0)

看起来32位和64位有一些差异,以及框架版本。我在x64上的4.0.0.0版本有这些选项暗示:

        //
        // Summary:
        //     The directory for components that are shared across applications.To get the
        //     x86 common program files directory on a non-x86 system, use the System.Environment.SpecialFolder.ProgramFilesX86
        //     member.
        CommonProgramFiles = 43,
        //
        // Summary:
        //     The Program Files folder. Added in the .NET Framework 4.
        CommonProgramFilesX86 = 44,
        //
        // Summary:
        //     The file system directory that contains the templates that are available
        //     to all users. This special folder is valid only for Windows NT systems. Added
        //     in the .NET Framework 4.
        CommonTemplates = 45,
        //
        // Summary:
        //     The file system directory that contains documents that are common to all
        //     users. This special folder is valid for Windows NT systems, Windows 95, and
        //     Windows 98 systems with Shfolder.dll installed. Added in the .NET Framework 4.
        CommonDocuments = 46,
        //
        // Summary:
        //     The file system directory that contains administrative tools for all users
        //     of the computer. Added in the .NET Framework 4.
        CommonAdminTools = 47,

有关MSDN的更多信息。尝试更改框架版本并查看其更改方式