windowsphone如何申请资源?
How to include resources to application for windows phone?
我有一个问题:我为 windows phone(在 VS 2013 中)创建了新的 c# 项目并将测试文件 属性 设置为 "Copy if newer",但我不能查看模拟器本地文件夹中的文件。我做错了什么?
更详细:
- 创建应用:
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
如何将文件包含到应用程序并在模拟器上访问它?
限制:
我确实需要在本地存储上保存数据(没有网络链接,没有云)
如果你想访问包中的文件,那么你需要使用 Package.InstalledLocation, you won't find those files in ApplicationData.LocalFolder。
请注意,Package 中包含的文件是只读,您将无法写入它们。
您还可以找到更多信息 at this answer。
我有一个问题:我为 windows phone(在 VS 2013 中)创建了新的 c# 项目并将测试文件 属性 设置为 "Copy if newer",但我不能查看模拟器本地文件夹中的文件。我做错了什么?
更详细:
- 创建应用:
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
如何将文件包含到应用程序并在模拟器上访问它?
限制: 我确实需要在本地存储上保存数据(没有网络链接,没有云)
如果你想访问包中的文件,那么你需要使用 Package.InstalledLocation, you won't find those files in ApplicationData.LocalFolder。
请注意,Package 中包含的文件是只读,您将无法写入它们。
您还可以找到更多信息 at this answer。