Search code examples
windows-phone-7windows-phone-8isolatedstoragewindows-phone-8-emulator

How to export the Sqlite file in root of the application in windows phone


enter image description here

Hi my Sqlite file is placed in root of the application. When I use Isolated explorer tool

ISETool.exe ts xd f8ce6878-0aeb-497f-bcf4-65be961d4bba c:\data\myfiles

I didn't get the Notes_DB.sqlite in isolates storage.

How coudld I get the modified sqlite file in the emulator.

Thanks in advance.


Solution

  • Isolated Storage Explorer does exactly what it says, lists the files in isolated storage. When you add a file in the XAP, it resides in the installation folder and not isolated storage.

    You could use the following code to copy the file from your installation folder to isolatedstorage (modified from this example http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202978(v=vs.105).aspx)

    private void CopyFileToStorage()
    {
       using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
       {
          if (!storage.FileExists("Notes_DB.sqlite"))
            {
                // Open the file from the XAP
                StreamResourceInfo resource = Application.GetResourceStream(new Uri("Notes_DB.sqlite", UriKind.Relative));
    
                using (IsolatedStorageFileStream file = storage.CreateFile("Notes_DB.sqlite"))
                {
                    int chunkSize = 4096;
                    byte[] bytes = new byte[chunkSize];
                    int byteCount;
    
                    while ((byteCount = resource.Stream.Read(bytes, 0, chunkSize)) > 0)
                    {
                        file.Write(bytes, 0, byteCount);
                    }
                }
              }
        }
    }