我遇到了一个问题:我为Windows Phone创建了新的c#项目(在VS 2013中),并将测试文件属性设置为“Copy if newer”,但我无法在模拟器的Local文件夹中看到该文件。我做错了什么?
更详细:
File->New->Project->Templates->Visual C#->Store Apps->Windows Phone Apps->Blank App (Windows Phone)
设置测试文件属性
在模拟器上运行(有一个按钮)和列表文件,代码为:
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();
}
}
}
使用Windows Phone Power Tools检查文件。本地文件夹仅包含log.txt。日志包含本地目录和日志文件。没有TestText.txt
如何将文件包含到应用程序并在模拟器上访问它?
限制: 我确实需要保存本地存储数据(没有网络链接,没有云端)
答案 0 :(得分:2)
如果您想访问软件包附带的文件,则需要使用Package.InstalledLocation,但您无法在ApplicationData.LocalFolder中找到这些文件。
请注意, Package 中包含的文件是只读,您将无法编写它们。
您还可以找到更多信息at this answer。