哪里的FileStream在.NET的Windows应用商店?商店、FileStream、NET、Windows

2023-09-02 10:32:43 作者:此用户不存在

我创建一个Windows应用商店的应用程序。 我需要为了写一些复杂的数据为一种专有的文件格式创建的FileStream。我想补充System.IO我的用途,但没有可用的FileStream。

I'm creating a Windows Store app. I need to create a FileStream in order to write some complex data for a proprietary file format. I add System.IO to my uses, but there's no FileStream available.

我调查的更多一些,而.NET为Windows应用商店应用服务概述关于IsolatedStorage指导讲座,此库甚至不使用当前。 一些阅读后,我认为真正的替代可能是FileRandomAccessStream,从nacemspace:Windows.Storage.Streams

I've investigating some more, and the ".NET for Windows Store apps overview" guide talks about IsolatedStorage, which this library don't even use currently. After some reading, I think the real replacement could be FileRandomAccessStream, from the nacemspace: Windows.Storage.Streams

什么是真正相当于对FILESTREAM在Windows应用商店的应用程序使用?

What is the real equivalent to FileStream to use in a Windows Store app?

推荐答案

事实上,沙箱在那里你可以从读/写诸多限制。下面是一些典型的地方:

Indeed, the sandbox has many limitations in where you can read from/write to. Here are some typical locations:

如果你想从您的应用程序的安装文件夹加载资源,可以使用以下命令:

If you are trying to load resources from your application's installation folder, you can use the following:

StorageFolder installFolder = Windows.ApplicationModel.Package.Current.InstalledLocation

StorageFile文件=等待StorageFile.GetFileFromApplicationUriAsync(MS-APPX:///file.txt);

(这是一个的只读的文件夹,因此你不能编辑或创建新的文件。)

(It is a read-only folder, so you cannot edit or create new files.)

如果你正在尝试将数据写入文件到您的应用程序的数据文件夹,您可以使用以下命令:

If you are trying to write data files to your application's data folder, you can use the following:

StorageFolder localFolder = ApplicationData.Current.LocalFolder;

StorageFile文件=等待StorageFile.GetFileFromApplicationUriAsync(MS-应用程序数据:///local/file.txt);

(该文件夹的读写的,您也可以访问的漫游或临时文件夹,通​​过改变本地其他两个中的一个。)

(This folder is read-write. You can also access roaming or temporary folders by changing local to one of the other two.)

有一些其他的文件夹以及,如 DownloadsFolder ,虽然你只能访问的文件,你的应用程序下载。

There are some other folders as well, such as the DownloadsFolder, although you can only access files that your application downloads.

另外,您也可以随时要求进行权限的用户使用 FileOpenPicker FileSavePicker 。拣货员做的不可以允许访问 InstalledLocation 路径,但将允许您访问文件图片下载(即使你的应用程序没有下载文件)。

Alternatively, you can always ask the user for permission with FileOpenPicker and FileSavePicker. The pickers do not allow access to the InstalledLocation path, but will allow you to access Documents, Pictures, and Downloads (even if your app did not download the file).