What directories do the different Application SpecialFolders point to in WindowsXP and Windows Vista

后端 未结 3 593
离开以前
离开以前 2020-12-15 04:23

Namely I have:

  • Environment.SpecialFolder.ApplicationData
  • Environment.SpecialFolder.CommonApplicationData
  • Envi
相关标签:
3条回答
  • 2020-12-15 04:30

    There's no single answer to that. In fact, that's precisely why these "SpecialFolder"s are defined. You use those instead of a hardcoded path.

    Environment.SpecialFolder.ApplicationData is the most common one. This folder holds per-user, non-temporary application-specific data, other than user documents. A common example would be a settings or configuration file.

    Environment.SpecialFolder.CommonApplicationData is similar, but shared across users. You could use this to store document templates, for instance.

    Environment.SpecialFolder.LocalApplicationData is a non-roaming alternative for ApplicationData. As such, you'd never store important data there. However, because it's non-roaming it is a good location for temporary files, caches, etcetera. It's typically on a local disk.

    0 讨论(0)
  • 2020-12-15 04:32

    It's easy to check. Use Environment.GetFolderPath(...); and use MessageBox or Console.Write and it will show you where it points too. You only have to make simple app that will display paths for you, and run it under Windows XP and Windows Vista.

    using System;
    
    namespace EnvironmentCheck
    {
        class Program
        {
            static void Main(string[] args)
        {
            Console.Write(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\n");
            Console.Write(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)+ "\n");
            Console.Write(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)+ "\n");
        }
    }
    }
    

    My results on Win 7 x64

    C:\Users\myUsername\AppData\Roaming
    C:\ProgramData
    C:\Users\myUsername\AppData\Local

    0 讨论(0)
  • 2020-12-15 04:48

    For anyone who wants to know what these special folders evaluate to on Windows XP but don't have XP to run it on, here's what I get when running @MadBoy's code:

    ApplicationData:

    C:\Documents and Settings\YourAccountHere\Application Data
    

    CommonApplicationData:

    C:\Documents and Settings\All Users\Application Data
    

    LocalApplicationData:

    C:\Documents and Settings\YourAccountHere\Local Settings\Application Data
    
    0 讨论(0)
提交回复
热议问题