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

后端 未结 5 915
傲寒
傲寒 2021-01-29 20:22

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:57

    Output on Ubuntu 9.10 -> Ubuntu 12.04 with mono 2.10.8.1:

    SpecialFolder.ApplicationData: /home/$USER/.config
    SpecialFolder.CommonApplicationData: /usr/share
    SpecialFolder.ProgramFiles: 
    SpecialFolder.DesktopDirectory: /home/$USER/Desktop
    SpecialFolder.LocalApplicationData: /home/$USER/.local/share
    SpecialFolder.MyDocuments: /home/$USER
    SpecialFolder.System: 
    
    SpecialFolder.Personal: /home/$USER
    

    Output on Ubuntu 16.04 with mono 4.2.1

    SpecialFolder.ApplicationData: /home/$USER/.config
    SpecialFolder.CommonApplicationData: /usr/share
    SpecialFolder.ProgramFiles:
    SpecialFolder.DesktopDirectory: /home/$USER/Desktop
    SpecialFolder.LocalApplicationData: /home/$USER/.local/share
    SpecialFolder.MyDocuments: /home/$USER
    SpecialFolder.Desktop: /home/$USER/Desktop
    SpecialFolder.Personal: /home/$USER
    
    SpecialFolder.System: 
    SpecialFolder.Programs: 
    SpecialFolder.Favorites: 
    SpecialFolder.Startup: 
    SpecialFolder.Recent: 
    SpecialFolder.SendTo: 
    SpecialFolder.StartMenu: 
    SpecialFolder.MyMusic: /home/$USER/Music
    SpecialFolder.MyVideos: /home/$USER/Videos
    SpecialFolder.MyComputer: 
    SpecialFolder.NetworkShortcuts: 
    SpecialFolder.Fonts: /home/$USER/.fonts
    SpecialFolder.Templates: /home/$USER/Templates
    SpecialFolder.CommonStartMenu: 
    SpecialFolder.CommonPrograms: 
    SpecialFolder.CommonStartup: 
    SpecialFolder.CommonDesktopDirectory: 
    SpecialFolder.PrinterShortcuts: 
    SpecialFolder.InternetCache: 
    SpecialFolder.Cookies: 
    SpecialFolder.History: 
    SpecialFolder.Windows: 
    SpecialFolder.MyPictures: /home/$USER/Pictures
    SpecialFolder.UserProfile: /home/$USER
    SpecialFolder.SystemX86: 
    SpecialFolder.ProgramFilesX86: 
    SpecialFolder.CommonProgramFiles: 
    SpecialFolder.CommonProgramFilesX86: 
    SpecialFolder.CommonTemplates: /usr/share/templates
    SpecialFolder.CommonDocuments: 
    SpecialFolder.CommonAdminTools: 
    SpecialFolder.AdminTools: 
    SpecialFolder.CommonMusic: 
    SpecialFolder.CommonPictures: 
    SpecialFolder.CommonVideos: 
    SpecialFolder.Resources: 
    SpecialFolder.LocalizedResources: 
    SpecialFolder.CommonOemLinks: 
    SpecialFolder.CDBurning: 
    

    where $USER is the current user

    Output on Ubuntu 16.04 using dotnet core (3.0.100)

    ApplicationData: /home/$USER/.config
    CommonApplicationData: /usr/share
    ProgramFiles: 
    DesktopDirectory: /home/$USER/Desktop
    LocalApplicationData: /home/$USER/.local/share
    MyDocuments: /home/$USER
    System: 
    Personal: /home/$USER
    

    Output on Android 6 using Xamarin 7.2

    Environment.SpecialFolder.ApplicationData: /data/user/0/$APPNAME/files/.config
    Environment.SpecialFolder.CommonApplicationData: /usr/share
    Environment.SpecialFolder.ProgramFiles: 
    Environment.SpecialFolder.DesktopDirectory: /data/user/0/$APPNAME/files/Desktop
    Environment.SpecialFolder.LocalApplicationData: /data/user/0/$APPNAME/files/.local/share
    Environment.SpecialFolder.MyDocuments: /data/user/0/$APPNAME/files
    Environment.SpecialFolder.Desktop: /data/user/0/$APPNAME/files/Desktop
    Environment.SpecialFolder.Personal: /data/user/0/$APPNAME/files
    
    Environment.SpecialFolder.Startup: 
    Environment.SpecialFolder.Recent: 
    Environment.SpecialFolder.SendTo: 
    Environment.SpecialFolder.StartMenu: 
    Environment.SpecialFolder.MyMusic: /data/user/0/$APPNAME/files/Music
    Environment.SpecialFolder.MyVideos: /data/user/0/$APPNAME/files/Videos
    Environment.SpecialFolder.MyComputer: 
    Environment.SpecialFolder.NetworkShortcuts: 
    Environment.SpecialFolder.Fonts: /data/user/0/$APPNAME/files/.fonts
    Environment.SpecialFolder.Templates: /data/user/0/$APPNAME/files/Templates
    Environment.SpecialFolder.CommonStartMenu: 
    Environment.SpecialFolder.CommonPrograms: 
    Environment.SpecialFolder.CommonStartup: 
    Environment.SpecialFolder.CommonDesktopDirectory: 
    Environment.SpecialFolder.PrinterShortcuts: 
    Environment.SpecialFolder.InternetCache: 
    Environment.SpecialFolder.Cookies: 
    Environment.SpecialFolder.History: 
    Environment.SpecialFolder.Windows: 
    Environment.SpecialFolder.MyPictures: /data/user/0/$APPNAME/files/Pictures
    Environment.SpecialFolder.UserProfile: /data/user/0/$APPNAME/files
    Environment.SpecialFolder.SystemX86: 
    Environment.SpecialFolder.ProgramFilesX86: 
    Environment.SpecialFolder.CommonProgramFiles: 
    Environment.SpecialFolder.CommonProgramFilesX86: 
    Environment.SpecialFolder.CommonTemplates: /usr/share/templates
    Environment.SpecialFolder.CommonDocuments: 
    Environment.SpecialFolder.CommonAdminTools: 
    Environment.SpecialFolder.AdminTools: 
    Environment.SpecialFolder.CommonMusic: 
    Environment.SpecialFolder.CommonPictures: 
    Environment.SpecialFolder.CommonVideos: 
    Environment.SpecialFolder.Resources: 
    Environment.SpecialFolder.LocalizedResources: 
    Environment.SpecialFolder.CommonOemLinks: 
    Environment.SpecialFolder.CDBurning: 
    

    Where $APPNAME is the name of your Xamarin application (eg. MyApp.Droid)

    Output on iOS Simulator 10.3 using Xamarin 7.2

    ApplicationData: /Users/$USER/Library/Developer/CoreSimulator/Devices/$DEVICEGUID/data/Containers/Data/Application/$APPLICATIONGUID/Documents/.config
    CommonApplicationData: /usr/share
    ProgramFiles: /Applications
    DesktopDirectory: /Users/$USER/Library/Developer/CoreSimulator/Devices/$DEVICEGUID/data/Containers/Data/Application/$APPLICATIONGUID/Documents/Desktop
    LocalApplicationData: /Users/$USER/Library/Developer/CoreSimulator/Devices/$DEVICEGUID/data/Containers/Data/Application/$APPLICATIONGUID/Documents
    MyDocuments: /Users/$USER/Library/Developer/CoreSimulator/Devices/$DEVICEGUID/data/Containers/Data/Application/$APPLICATIONGUID/Documents
    Desktop: /Users/$USER/Library/Developer/CoreSimulator/Devices/$DEVICEGUID/data/Containers/Data/Application/$APPLICATIONGUID/Documents/Desktop
    MyDocuments: /Users/$USER/Library/Developer/CoreSimulator/Devices/$DEVICEGUID/data/Containers/Data/Application/$APPLICATIONGUID/Documents
    Startup: 
    Recent: 
    SendTo: 
    StartMenu: 
    MyMusic: /Users/$USER/Library/Developer/CoreSimulator/Devices/$DEVICEGUID/data/Containers/Data/Application/$APPLICATIONGUID/Documents/Music
    MyVideos: /Users/$USER/Library/Developer/CoreSimulator/Devices/$DEVICEGUID/data/Containers/Data/Application/$APPLICATIONGUID/Documents/Videos
    MyComputer: 
    NetworkShortcuts: 
    Fonts: /Users/$USER/Library/Developer/CoreSimulator/Devices/$DEVICEGUID/data/Containers/Data/Application/$APPLICATIONGUID/Documents/.fonts
    Templates: /Users/$USER/Library/Developer/CoreSimulator/Devices/$DEVICEGUID/data/Containers/Data/Application/$APPLICATIONGUID/Documents/Templates
    CommonStartMenu: 
    CommonPrograms: 
    CommonStartup: 
    CommonDesktopDirectory: 
    PrinterShortcuts: 
    InternetCache: /Users/$USER/Library/Developer/CoreSimulator/Devices/$DEVICEGUID/data/Containers/Data/Application/$APPLICATIONGUID/Library/Caches
    Cookies: 
    History: 
    Windows: 
    MyPictures: /Users/$USER/Library/Developer/CoreSimulator/Devices/$DEVICEGUID/data/Containers/Data/Application/$APPLICATIONGUID/Documents/Pictures
    UserProfile: /Users/$USER/Library/Developer/CoreSimulator/Devices/$DEVICEGUID/data/Containers/Data/Application/$APPLICATIONGUID
    SystemX86: 
    ProgramFilesX86: 
    CommonProgramFiles: 
    CommonProgramFilesX86: 
    CommonTemplates: /usr/share/templates
    CommonDocuments: 
    CommonAdminTools: 
    AdminTools: 
    CommonMusic: 
    CommonPictures: 
    CommonVideos: 
    Resources: /Users/$USER/Library/Developer/CoreSimulator/Devices/$DEVICEGUID/data/Containers/Data/Application/$APPLICATIONGUID/Library
    LocalizedResources: 
    CommonOemLinks: 
    CDBurning: 
    

    Where $DEVICEGUID is the simulator GUID (depending on the selected simulator)

    Output on ipad 10.3 using Xamarin 7.2

    SpecialFolder.MyDocuments: /var/mobile/Containers/Data/Application/$APPLICATIONGUID/Documents
    

    Output on ipad 13.3 using Xamarin 16.4

    SpecialFolder.MyDocuments: /var/mobile/Containers/Data/Application/$APPLICATIONGUID/Documents
    SpecialFolder.UserProfile: /private/var/mobile/Containers/Data/Application/$APPLICATIONGUID/Documents
    

    Output on windows 10 using .net core 3.1

    SpecialFolder.MyDocuments: C:\Users\$USER\Documents
    

    Output on Ubuntu 18.04 using .net core 3.1

    SpecialFolder.MyDocuments: /home/$USER
    

    Output on MacOS Catalina using .net core 3.1

    SpecialFolder.MyDocuments: /Users/$USER
    

提交回复
热议问题