

My app then gets the weblink that points to the file. This section describes the platform-specific differences with the file system helpers.I have implemented the OneDrive picker in my app to allow the user to easily select a file from the OneDrive cloud storage. Using FileStream outputStream = File.Create(targetFile) Īwait inputStream.CopyToAsync(outputStream) String targetFile = Path.Combine(, filename) Using Stream inputStream = await (filename) The following example uses OpenAppPackageFileAsync to copy a bundled file to the app data folder: public async Task CopyFileToAppDataDirectory(string filename) But you can copy a bundled file to the cache directory or app data directory. Using StreamReader reader = new StreamReader(fileStream) Ĭopy a bundled file to the app data folder Using Stream fileStream = await (filePath) The following example demonstrates using a method to read the text contents of a file: public async Task ReadTextFile(string filePath)

This method returns a read-only Stream representing the file contents. To open a file that is bundled into the app package, use the OpenAppPackageFileAsync method and pass the file name. These files are backed up with the operating system syncing framework. To get the app's top-level directory for any files that aren't user data files. Cache data can be used for any data that needs to persist longer than temporary data, but shouldn't be data that is required to operate the app, as the operating system may clear this storage. To get the application's directory to store cache data.

The IFileSystem interface provides a cross-platform API for accessing these directory paths. Using file system helpersĮach operating system will have unique paths to the app cache and app data directories. Both the IFileSystem interface and FileSystem class are contained in the namespace. The default implementation of the IFileSystem interface is available through the FileSystem.Current property. This interface provides helper methods that access the app's cache and data directories, and helps access files in the app package. NET Multi-platform App UI (.NET MAUI) IFileSystem interface.

This article describes how you can use the.
