2

I'm trying to store a local SQLite database in the internal storage of the device. When I was using an emulator , this:

static string dbName = "totems.sqlite";
string dbPath = Path.Combine (Android.OS.Environment.ExternalStorageDirectory.ToString (), dbName);

worked fine. But when I tried to debug on my Nexus 5, it didn't work, because it doesn't have external storage. I searched where to store it so it could run on my Nexus as well. I replaced it with:

static string dbName = "totems.sqlite";
string dbPath = Path.Combine ("/data/data/com.companyname.totem/databases/", dbName);

But now it doesn't work on my Nexus 5 and it doesn't work on my emulator. It says it can't find the path.

What am I doing wrong?

Thanks in advance.

3 Answers 3

4

I know this is an old thread, but the old answer has a typo. The working syntax should be :

string path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "DatabaseName.txt");
Sign up to request clarification or add additional context in comments.

Comments

1

Im using the following code:

string path = Path.Combine(System.Enviroment.GetFolderPath(System.Enviroment.SpecialFolder.Personal), "data.txt");

I think that should write into the internal storage like you want

1 Comment

This is the way to go.
1

From docs.com

LocalApplicationData: The directory that serves as a common repository for application-specific data that is used by the current, non-roaming user.

Personal: The directory that serves as a common repository for documents. This member is equivalent to MyDocuments.

From this I use:

var db_directory = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData),"databases"))

var db_path = Path.Combine(db_directory,"data.db");

Also from this sample (XF)
docs.com xamarin tutorial

public static Database Database
        {
            get
            {
                if (database == null)
                {
                    database = new Database(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "people.db3"));
                }
                return database;
            }
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.