Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is FileStream at the .NET for Windows Store?

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?

like image 802
Craig Stevensson Avatar asked Jan 13 '13 00:01

Craig Stevensson


People also ask

Where is Microsoft Store file location?

Installation Folder Your Store downloads are in a hidden folder in Program Files > WindowsApps. Open File Explorer and click on the Program Files folder.

Where are the files for Windows Store apps?

The Universal or Windows Store Applications in Windows 10/8 are installed in the WindowsApps folder located in the C:\Program Files folder.

What is .NET for Windows Store apps?

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.

What is the file stream?

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.


2 Answers

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).

like image 165
Erik Avatar answered Nov 16 '22 17:11

Erik


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

like image 21
Lloyd Avatar answered Nov 16 '22 19:11

Lloyd