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.
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
What is the real equivalent to FileStream to use in a Windows Store app?
Installation Folder Your Store downloads are in a hidden folder in Program Files > WindowsApps. Open File Explorer and click on the Program Files folder.
The Universal or Windows Store Applications in Windows 10/8 are installed in the WindowsApps folder located in the C:\Program Files folder.
NET. . NET code can be used for user interface, business logic and background processing. You can continue to use . NET on the server too, as the implementation of REST, WCF or ODATA APIs that you call from within your Windows Store Apps.
A file stream is a sequence of bytes used to hold file data. Usually a file has only one file stream, namely the file's default data stream. However, on file systems that support multiple data streams, each file can have multiple file streams. One of these is the default data stream, which is unnamed.
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 file = await 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 file = await StorageFile.GetFileFromApplicationUriAsync("ms-appdata:///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.)
There are some other folders as well, such as the DownloadsFolder
, although you can only access files that your application downloads.
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).
Due to the sandbox environment Windows Store apps run in it has been replaced by StorageFile
. See here for the documentation:-
http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefile.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With