2

I have a problem: I created new c# project for windows phone (in VS 2013) and set test file property as "Copy if newer", but I cannot see file in emulator's Local folder. What do I do wrong?

More detailed:

  1. Create app: File->New->Project->Templates->Visual C#->Store Apps->Windows Phone Apps->Blank App (Windows Phone)
  2. set test file property TestText.txt isn't empty

  3. run on emulator (there is a button for this) and list files with code:

    async void listFolder()
    {
        StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
        Stack<StorageFolder> stack = new Stack<StorageFolder>();
        stack.Push(local);
    
        StorageFolder current;
        string path;
        byte[] bytes;
        StorageFile logFile = await local.CreateFileAsync("log.txt", CreationCollisionOption.ReplaceExisting);
        using (var s = await logFile.OpenStreamForWriteAsync())
        {
            while (stack.Count > 0)
            {
                current = stack.Pop();
                foreach (StorageFolder f in await current.GetFoldersAsync())
                {
                    stack.Push(f);
                }
                path = current.Path;
                bytes = Encoding.UTF8.GetBytes(current.Path + "\n");
                s.Write(bytes, 0, bytes.Length);
                foreach (StorageFile f in await current.GetFilesAsync())
                {
                    bytes = Encoding.UTF8.GetBytes(f.Path + "\n");
                    s.Write(bytes, 0, bytes.Length);
                }
                s.Flush();
            }
        }
    }
    
  4. Check file with Windows Phone Power Tools. Local folder contains log.txt only. Log contains Local directory and log file. No TestText.txt

How do I include file to application and access it on emulator?

Limitations: I do need to held data on local storage (no web links, no cloud)

Romasz
  • 29,662
  • 13
  • 79
  • 154
Sergey Fedorov
  • 2,169
  • 1
  • 15
  • 26
  • 1
    You need to read the file from package not local folder - it's not the same. [This answer](http://stackoverflow.com/a/24339587/2681948) should help. Also remember that *Package* is *read-only* - so you will be able to get files from it but not write them. – Romasz Feb 04 '15 at 10:32
  • @Romasz Thanks for comment! I would accept it if you turn it into an answer. – Sergey Fedorov Feb 04 '15 at 11:02
  • No problem. I've turned it into answer as it may be easier to find that the one from the link. – Romasz Feb 04 '15 at 11:10

1 Answers1

2

If you want to access files that come with your package, then you need to use Package.InstalledLocation, you won't find those files in ApplicationData.LocalFolder.

Note that files included in Package are read-only and you won't be able to write them.

Some more information you will also find at this answer.

Community
  • 1
  • 1
Romasz
  • 29,662
  • 13
  • 79
  • 154