Environment.GetFolderPath(…CommonApplicationData) is still returning “C:\Documents and Settings\” on Vista

后端 未结 5 448
北海茫月
北海茫月 2021-01-29 20:37

As I understand it, you\'re supposed to use the Environment.GetFolderPath method so you have OS independent code...

Windows XP uses C:\\Documents and

5条回答
  •  盖世英雄少女心
    2021-01-29 20:39

    I was looking for a listing of macOS but found nothing, maybe this helps someone.

    Output on macOS Catalina (10.15.7) using net5.0

    # SpecialFolders (Only with value)
    SpecialFolder.ApplicationData: /Users/$USER/.config
    SpecialFolder.CommonApplicationData: /usr/share
    SpecialFolder.Desktop: /Users/$USER/Desktop
    SpecialFolder.DesktopDirectory: /Users/$USER/Desktop
    SpecialFolder.Favorites: /Users/$USER/Library/Favorites
    SpecialFolder.Fonts: /Users/$USER/Library/Fonts
    SpecialFolder.InternetCache: /Users/$USER/Library/Caches
    SpecialFolder.LocalApplicationData: /Users/$USER/.local/share
    SpecialFolder.MyDocuments: /Users/$USER
    SpecialFolder.MyMusic: /Users/$USER/Music
    SpecialFolder.MyPictures: /Users/$USER/Pictures
    SpecialFolder.ProgramFiles: /Applications
    SpecialFolder.System: /System
    SpecialFolder.UserProfile: /Users/$USER
    
    # SpecialFolders (All)
    SpecialFolder.AdminTools: 
    SpecialFolder.ApplicationData: /Users/$USER/.config
    SpecialFolder.CDBurning: 
    SpecialFolder.CommonAdminTools: 
    SpecialFolder.CommonApplicationData: /usr/share
    SpecialFolder.CommonDesktopDirectory: 
    SpecialFolder.CommonDocuments: 
    SpecialFolder.CommonMusic: 
    SpecialFolder.CommonOemLinks: 
    SpecialFolder.CommonPictures: 
    SpecialFolder.CommonProgramFiles: 
    SpecialFolder.CommonProgramFilesX86: 
    SpecialFolder.CommonPrograms: 
    SpecialFolder.CommonStartMenu: 
    SpecialFolder.CommonStartup: 
    SpecialFolder.CommonTemplates: 
    SpecialFolder.CommonVideos: 
    SpecialFolder.Cookies: 
    SpecialFolder.Desktop: /Users/$USER/Desktop
    SpecialFolder.DesktopDirectory: /Users/$USER/Desktop
    SpecialFolder.Favorites: /Users/$USER/Library/Favorites
    SpecialFolder.Fonts: /Users/$USER/Library/Fonts
    SpecialFolder.History: 
    SpecialFolder.InternetCache: /Users/$USER/Library/Caches
    SpecialFolder.LocalApplicationData: /Users/$USER/.local/share
    SpecialFolder.LocalizedResources: 
    SpecialFolder.MyComputer: 
    SpecialFolder.MyDocuments: /Users/$USER
    SpecialFolder.MyMusic: /Users/$USER/Music
    SpecialFolder.MyPictures: /Users/$USER/Pictures
    SpecialFolder.MyVideos: 
    SpecialFolder.NetworkShortcuts: 
    SpecialFolder.PrinterShortcuts: 
    SpecialFolder.ProgramFiles: /Applications
    SpecialFolder.ProgramFilesX86: 
    SpecialFolder.Programs: 
    SpecialFolder.Recent: 
    SpecialFolder.Resources: 
    SpecialFolder.SendTo: 
    SpecialFolder.StartMenu: 
    SpecialFolder.Startup: 
    SpecialFolder.System: /System
    SpecialFolder.SystemX86: 
    SpecialFolder.Templates: 
    SpecialFolder.UserProfile: /Users/$USER
    SpecialFolder.Windows: 
    

    I have replaced my username with $USER.

    Code Snippet from pogosama.

    foreach(Environment.SpecialFolder f in Enum.GetValues(typeof(Environment.SpecialFolder)))
    {
        string commonAppData = Environment.GetFolderPath(f);
        Console.WriteLine("{0}: {1}", f, commonAppData);
    }
    Console.ReadLine();
    

提交回复
热议问题