What is the best Environment.SpecialFolder for store application data in Xamarin.Forms?
Asked Answered
T

1

27

I'm new in Xamarin.Forms and mobile development. I want to store user and encrypted password of my application user in file on mobile device. I'm using xamarin forms technology. I kwnow that there are many differenet folders. In example:

System.Environment.SpecialFolder.Personal
System.Environment.SpecialFolder.LocalApplicationData
System.Environment.SpecialFolder.MyDocuments

Full list you can find here: https://msdn.microsoft.com/en-gb/en-enl/library/system.environment.specialfolder(v=vs.110).aspx

What is the best folder / catalog for store:

  • user and password data
  • other application specyfic data

??

Edit: I have found that "Personal" is good for me, but if you have other answers post it as well. SpecialFolder.Personal location

Telescope answered 11/11, 2017 at 11:30 Comment(0)
B
44

Storing small Key-Value Pairs:

Xamarin.Forms implements Application.Current.Properties which stores the key value data in the local storage of the app and access to these key-value pairs are secure to that app only who stored them.

Storing Documents/Database (Sqlite):

Each platform has it's own folder structure to store app specific data/files underneath.

Android:

Environment.SpecialFolder.Personal & MyDocuments both maps to: /data/data/@PACKAGE_NAME@/files

Environment.SpecialFolder.LocalApplicationData maps to: /data/data/@PACKAGE_NAME@/files/.local/share

We can store files in any of the above directories based on how they are mapped in the file system. None of the above directories can be accessed by other app, nor user can access them outside the world unless the phone is rooted.

iOS:

Environment.SpecialFolder.Personal, LocalApplicationData & MyDocuments all map to: /Documents

iOS has following directory structure:

/Documents
/Library
/Library/Application Support
/Library/Caches
/tmp

/Documents: Gets visible in iTunes If iTunes sharing is turned on in info.plist in the app. Content can be backed up by iTunes/iCloud.

/Library: Not visible in iTunes. Can be backed up by iTunes/iCloud except Caches directory.

Files/Data which doesn't need to expose to user should be stored in Library directory. Ex. database files. I would go for Library directory for add on security along with encryption (if required).

To get to the Library Path:

Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments), "..", "Library");

To know more on each Enumeration's mapping with directory Go Here.

Find basics about iOS File System Basics.

Basswood answered 11/11, 2017 at 18:32 Comment(1)
Using Environment.SpecialFolder.Resources saves files to /LibraryDragon

© 2022 - 2024 — McMap. All rights reserved.