locked
System.Environment.SpecialFolder RRS feed

  • Question

  • User1669 posted

    I was looking at the API documentation for the SpecialFolder enumeration, and it appears it needs to be filled out. :) So my question is, in regards to Android, which file paths do these enumerations map to? Specifically, I'm interested in ApplicatonData, LocalApplicationData, and Personal. But it would be useful to know what these file paths are in Android and what type of data is appropriate to store in each location. Anyone know?

    http://androidapi.xamarin.com/?link=T%3aSystem.Environment%2bSpecialFolder

    Friday, May 3, 2013 3:50 PM

Answers

  • User48 posted

    Environment.SpecialFolder.ApplicationData is $HOME/.config, which is /data/data/@PACKAGE_NAME@/files/.config.

    Environment.SpecialFolder.LocalApplicationData is $HOME/.local/share, which is /data/data/@PACKAGE_NAME@/files/.local/share.

    Environment.SpecialFolder.Personal is $HOME, which is /data/data/@PACKAGE_NAME@/files.

    When in doubt, try-it-and-see:

    static void PrintFolderPath(System.Environment.SpecialFolder folder)
    {
        Console.WriteLine ("{0}={1}", folder, System.Environment.GetFolderPath(folder));
    }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, May 3, 2013 4:04 PM
  • User128366 posted

    For anyone here looking for iOS information:

    Posting this information here because this question is google's top result for "xamarin environment.specialfolder"

    Apple's documentation on iOS filesystem, and where to store things: https://developer.apple.com/library/mac/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html

    Folder path for each enum: Desktop= /Documents/Desktop MyDocuments= /Documents MyDocuments= /Documents Favorites= /Library/Favorites MyMusic= /Documents/Music MyVideos= /Documents/Videos DesktopDirectory= /Documents/Desktop Fonts= /Documents/.fonts Templates= /Documents/Templates ApplicationData= /Documents/.config LocalApplicationData= /Documents InternetCache= /Library/Caches CommonApplicationData= /usr/share ProgramFiles= /Applications MyPictures= /Documents/Pictures CommonTemplates= /usr/share/templates Resources= /Library

    Unused enums Programs= Startup= Recent= SendTo= StartMenu= MyComputer= NetworkShortcuts= CommonStartMenu= CommonPrograms= CommonStartup= CommonDesktopDirectory= PrinterShortcuts= Cookies= History= Windows= System= UserProfile= SystemX86= ProgramFilesX86= CommonProgramFiles= CommonProgramFilesX86= CommonDocuments= CommonAdminTools= AdminTools= CommonMusic= CommonPictures= CommonVideos= LocalizedResources= CommonOemLinks= CDBurning=

    Code to give you the paths for all enums (enhanced version of JonathanPryor's code) foreach (var folder in Enum.GetValues(typeof(Environment.SpecialFolder))) { Console.WriteLine("{0}={1}", folder, System.Environment.GetFolderPath((Environment.SpecialFolder)folder)); }

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, August 22, 2016 5:42 PM

All replies

  • User48 posted

    Environment.SpecialFolder.ApplicationData is $HOME/.config, which is /data/data/@PACKAGE_NAME@/files/.config.

    Environment.SpecialFolder.LocalApplicationData is $HOME/.local/share, which is /data/data/@PACKAGE_NAME@/files/.local/share.

    Environment.SpecialFolder.Personal is $HOME, which is /data/data/@PACKAGE_NAME@/files.

    When in doubt, try-it-and-see:

    static void PrintFolderPath(System.Environment.SpecialFolder folder)
    {
        Console.WriteLine ("{0}={1}", folder, System.Environment.GetFolderPath(folder));
    }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, May 3, 2013 4:04 PM
  • User1155 posted

    This was a helpful answer... but, and I don't like to gripe... but I looked for the answer in the API documentation first. Then I spent time searching the forums. And, sure, I can write code and do experiments, but why not just complete the online API documentation? We'll get even more developers to stay on board with Xamarin if there is good documentation.

    Thursday, October 24, 2013 5:40 AM
  • User83725 posted

    Hi,

    I know that this thread is quite old, but Xamarin Android documentation recommends to store sqlite dbs in Environment.SpecialFolder.Personal, while the official Android documentation recommends Application.Context.GetDatabasePath(dbFileName) because this folder is not deleted in case of an app update. (the returned path is not under '/data/data/@PACKAGENAME@/files/, but under '/data/data/@PACKAGENAME@/databases/', which would seem coherent).

    2 questions:

    Why if I use the path returned by Application.Context.GetDatabasePath(dbFileName), SqLite fails with an exception, saying that it cannot open this path?

    Is Environment.SpecialFolder.Personal kept in case of an app update?

    Thank you for your help.

    Tuesday, January 13, 2015 1:59 PM
  • User101859 posted

    +1 for completing the documentation. Try searching for SpecialFolder and then click on the autocomplete link: Error: Your request has found no candidate provider [hs="(null)", id="(null)"]

    Tuesday, May 12, 2015 1:57 PM
  • User89714 posted

    @remiguittaut - Did you ever find/receive an answer to your question above?

    Thanks,

    John H.

    Tuesday, September 8, 2015 10:00 AM
  • User177770 posted

    Bump. Need that answer too please. Thanks!

    Friday, January 29, 2016 9:16 PM
  • User212005 posted

    Bump. Looking for answer as well.

    Friday, May 13, 2016 1:22 PM
  • User128366 posted

    For anyone here looking for iOS information:

    Posting this information here because this question is google's top result for "xamarin environment.specialfolder"

    Apple's documentation on iOS filesystem, and where to store things: https://developer.apple.com/library/mac/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html

    Folder path for each enum: Desktop= /Documents/Desktop MyDocuments= /Documents MyDocuments= /Documents Favorites= /Library/Favorites MyMusic= /Documents/Music MyVideos= /Documents/Videos DesktopDirectory= /Documents/Desktop Fonts= /Documents/.fonts Templates= /Documents/Templates ApplicationData= /Documents/.config LocalApplicationData= /Documents InternetCache= /Library/Caches CommonApplicationData= /usr/share ProgramFiles= /Applications MyPictures= /Documents/Pictures CommonTemplates= /usr/share/templates Resources= /Library

    Unused enums Programs= Startup= Recent= SendTo= StartMenu= MyComputer= NetworkShortcuts= CommonStartMenu= CommonPrograms= CommonStartup= CommonDesktopDirectory= PrinterShortcuts= Cookies= History= Windows= System= UserProfile= SystemX86= ProgramFilesX86= CommonProgramFiles= CommonProgramFilesX86= CommonDocuments= CommonAdminTools= AdminTools= CommonMusic= CommonPictures= CommonVideos= LocalizedResources= CommonOemLinks= CDBurning=

    Code to give you the paths for all enums (enhanced version of JonathanPryor's code) foreach (var folder in Enum.GetValues(typeof(Environment.SpecialFolder))) { Console.WriteLine("{0}={1}", folder, System.Environment.GetFolderPath((Environment.SpecialFolder)folder)); }

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, August 22, 2016 5:42 PM
  • User262740 posted

    Yay. No answer as of November / 16.

    Thursday, November 10, 2016 12:30 PM
  • User247780 posted

    I found the answer. . Create separate class in your android project. . Use the following assembly references and erase all the default..,

    using System; using System.IO; using Xamarin.Forms; using (your android project).Droid; . . It worked for me

    Friday, February 3, 2017 12:12 AM
  • User283325 posted

    I repeat. Is Environment.SpecialFolder.Personal kept in case of an app update?

    Wednesday, February 15, 2017 6:03 PM
  • User244580 posted

    I found Ryan Ehrler's comment very useful, so I went ahead and ran his loop on Android.

    Do note that the SpecialFolder enum actually maps SpecialFolder.Personal and SpecialFolder.MyDocuments to the same integer value (5), which is why MyDocuments shows up in these lists twice and Personal doesn't at all.

    Folder path for each enum: ApplicationData=/files/.config CommonApplicationData=/usr/share CommonTemplates=/usr/share/templates DesktopDirectory=/files/Desktop Fonts=/files/.fonts LocalApplicationData=/files/.local/share MyDocuments=/files MyDocuments=/files MyMusic=/files/Music MyPictures=/files/Pictures MyVideos=/files/Videos Templates=/files/Templates UserProfile=/files

    Unused enums: AdminTools= CDBurning= CommonAdminTools= CommonDesktopDirectory= CommonDocuments= CommonMusic= CommonOemLinks= CommonPictures= CommonProgramFiles= CommonProgramFilesX86= CommonPrograms= CommonStartMenu= CommonStartup= CommonVideos= Cookies= Favorites= History= InternetCache= LocalizedResources= MyComputer= NetworkShortcuts= PrinterShortcuts= ProgramFiles= ProgramFilesX86= Recent= Resources= SendTo= StartMenu= Startup= System= SystemX86= Windows=

    Thursday, March 2, 2017 4:15 PM