locked
how to add a SQLite file to my app package

    Question

  • My application will open a  SQLite file when Initializing ,

    now ,I can read SQLite file in my code...

    but when I create a publish package by "Create App Package", I don't know how to add the file to my Package ?

    And which folder it will be placed ??

    Wednesday, August 21, 2013 8:35 AM

Answers

  • Check out  http://code.msdn.microsoft.com/windowsapps/Sqlite-For-Windows-8-Metro-2ec7a882 under lesson 2.  Here is a summary of that code. I happened to read this earlier today but haven't actually tried it myself. Hope it offers some clue. 

    public void CopyProjectFile()
    {
        try
        {
            var uri = new Uri("ms-appx:///data.db3"); //in application folder
            var file = await StorageFile.GetFileFromApplicationUriAsync(uri);

            await file.CopyAsync(ApplicationData.Current.LocalFolder); //copied application local  folder

        }
        catch { }
    }


    DeltaRanger256

    Friday, August 23, 2013 12:15 AM
  • To add the file to your app package you need to include it in your project and edit its properties so it is marked as content and to copy to the output directory. This will cause the file to be deployed with the app in its install directory.

    The kicker for a database is that the install directory is read-only, so you won't be able to modify the database there. Instead you can fill it with basic initialization data and then copy the database to ApplicationData.LocalFolder when the user first runs the app.

    --Rob

    Wednesday, August 21, 2013 10:10 PM
    Moderator

All replies

  • To add the file to your app package you need to include it in your project and edit its properties so it is marked as content and to copy to the output directory. This will cause the file to be deployed with the app in its install directory.

    The kicker for a database is that the install directory is read-only, so you won't be able to modify the database there. Instead you can fill it with basic initialization data and then copy the database to ApplicationData.LocalFolder when the user first runs the app.

    --Rob

    Wednesday, August 21, 2013 10:10 PM
    Moderator
  • Hi Bob Caplan: 1. add it to my project,and edit it's property as : content & copy always. 2. build package,,install.go to: C:\Users\zhouxj\AppData\Local\Packages I didn't find the .db file in the installation folder ?? Actually ,I want the .db file in the following folder: C:\Users\zhouxj\AppData\Local\Packages\***\LocalState 3.Instead you can fill it with basic initialization data and then copy the database to ApplicationData.LocalFolder when the user first runs the app what does this mean ? and what should I do ?? thank you !
    Thursday, August 22, 2013 1:47 AM
  • You cannot install files directly to the AppData directory. If the file is included correctly it will be installed alongside the app in the app's install directory.

    The app can copy it the file to the AppData directory itself when the app runs.

    --Rob

    Thursday, August 22, 2013 5:35 AM
    Moderator
  • Hi Bob Caplan: Question 1: I have done this: 1. add .db file to my project,and edit it's property as : content & copy always. 2. build package,,install After finish installation, Where is the .db file ?? Question 2: You mean I should Copy the .db file in my Initialize Code ? but I don't know the source path.. Is there any document about the total process ?
    Thursday, August 22, 2013 6:44 AM
  • Check out  http://code.msdn.microsoft.com/windowsapps/Sqlite-For-Windows-8-Metro-2ec7a882 under lesson 2.  Here is a summary of that code. I happened to read this earlier today but haven't actually tried it myself. Hope it offers some clue. 

    public void CopyProjectFile()
    {
        try
        {
            var uri = new Uri("ms-appx:///data.db3"); //in application folder
            var file = await StorageFile.GetFileFromApplicationUriAsync(uri);

            await file.CopyAsync(ApplicationData.Current.LocalFolder); //copied application local  folder

        }
        catch { }
    }


    DeltaRanger256

    Friday, August 23, 2013 12:15 AM
  • Hi MCinSeattle:

    It works!

    thanks for your example!

    Friday, August 23, 2013 1:47 AM