如何将资源包含到Windows Phone的应用程序中?

时间:2015-02-04 10:21:45

标签: visual-studio visual-studio-2013 windows-phone windows-phone-8.1

我遇到了一个问题:我为Windows Phone创建了新的c#项目(在VS 2013中),并将测试文件属性设置为“Copy if newer”,但我无法在模拟器的Local文件夹中看到该文件。我做错了什么?

更详细:

  1. 创建应用: File->New->Project->Templates->Visual C#->Store Apps->Windows Phone Apps->Blank App (Windows Phone)
  2. 设置测试文件属性 TestText.txt isn't empty

  3. 在模拟器上运行(有一个按钮)和列表文件,代码为:

    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. 使用Windows Phone Power Tools检查文件。本地文件夹仅包含log.txt。日志包含本地目录和日志文件。没有TestText.txt

  5. 如何将文件包含到应用程序并在模拟器上访问它?

    限制: 我确实需要保存本地存储数据(没有网络链接,没有云端)

1 个答案:

答案 0 :(得分:2)

如果您想访问软件包附带的文件,则需要使用Package.InstalledLocation,但您无法在ApplicationData.LocalFolder中找到这些文件。

请注意, Package 中包含的文件是只读,您将无法编写它们。

您还可以找到更多信息at this answer