Get Local Folders from App WinRT(从 App WinRT 获取本地文件夹)
问题描述
我在尝试将文件保存到我正在使用的 WinRT 应用程序的文件夹中时遇到问题.更具体地说:我无法检索文件夹.我需要保存一些文件,然后从同一个文件夹中检索它们,比如说 MyFolder
实际上在应用程序中与 Assets
文件夹处于同一级别.我怎样才能做到这一点?
I'm having an issue trying to save a file into a folder of the WinRT app I'm working at. More specific : I can't manage to retrieve the folder. I need to save some files and afterwards to retrieve them from that same folder, let's say MyFolder
which is actually at the same level in the app with the Assets
folder. How can I achieve such thing?
到目前为止我尝试过
await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("MyFolder")
和
await ApplicationData.Current.LocalFolder.GetFolderAsync("MyFolder");
两者似乎都告诉我这样的文件夹不存在.现在,我似乎无法弄清楚我是否在正确的轨道上,或者这是我所做的愚蠢的事情并导致了那个异常.我不能真正发布整个代码,因为它实际上是一个更大的方法与其他调用的调用,等等.
and both seem to tell me that such folder doesn't exist. Now, I can't seem to figure it out if I'm on the right track or it's something foolish I've done and causes that exception. I can't really post the whole code, because it's actually a call to a larger method with other calls, and so on.
另外,我想知道(如果这些方法中的任何一个是正确的),如果应用程序获得更新,内容会受到任何影响(更好地说,丢失).
Also, I'd like to know (if any of these methods are correct), if the app gets an update, the content is affected in any way (better said, lost).
谢谢.
推荐答案
Windows.ApplicationModel.Package.Current.InstalledLocation 将为您提供应用程序包定义的文件系统",因此您会看到常用的 Asset 文件夹,例如,通过 URI ms-appx:///Assets
通过 InstalledLocation 或 ms-appx
方案访问的任何内容都是只读的,因为它是由您从 Visual Studio 部署的项目定义的.
Windows.ApplicationModel.Package.Current.InstalledLocation will give you the 'file system' defined by the application package, so you'd see you the commonly used Asset folder, for instance, via the URI ms-appx:///Assets
Anything accessed via InstalledLocation or the ms-appx
scheme is read-only because it's defined by the project you deployed from Visual Studio.
ApplicationData.Current.LocalFolder 允许您访问当前应用程序/用户拥有的文件系统"(并存储在 %AppData%/Local/Packages/
).您可以在此处创建您想要的任何结构来管理您的各种角色,并使用 ms-appdata:///local/DirLeve1/DirLeve2/File3
URI 来访问您的文件).该存储通过更新您的应用程序来保留,当然,您需要一种策略来更新与较新版本的应用程序交互所需的任何存储数据格式.
ApplicationData.Current.LocalFolder allows you to access the 'file system' owned by the current application/user (and stored at %AppData%/Local/Packages/<yourapppackage>/LocalState
). You can create whatever structure you want here to manage your various roles, and use the ms-appdata:///local/DirLeve1/DirLeve2/File3
URI to access your files). That storage is retained through updates to your application, though, of course, you'll need a strategy for updating whatever stored data formats are required to interact with the newer version of your application.
听起来您假设 LocalFolder 不能包含文件夹层次结构;它可以,因此您可以在 LocalFolder 引用下有一个最近的子文件夹并以这种方式处理.
It sounds like you're assuming LocalFolder cannot contain a folder hiearachy; it can, and so you could have a Recents subfolder for instance under the LocalFolder reference and handle things that way.
这篇关于从 App WinRT 获取本地文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 App WinRT 获取本地文件夹
基础教程推荐
- 将 XML 转换为通用列表 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01