# .NET Maui FileStream

181 Reputation points
2022-08-28T21:00:03.69+00:00

I'm converting an UWP app to a .NET Maui, but having an issue with FileStream. Here is my working code in the UWP app:

string binaryFile="Resources\Images\alpha.jpg"

 private async static Task<Stream> GetBinaryStream(string binaryFile)
{
var storageFile = await Package.Current.InstalledLocation.GetFileAsync(binaryFile);
}


I've tried multiple implementations, but I can't find an alternative to the line:

How do I replicate the UWP code to work with Maui?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
1,101 questions

1. 13,741 Reputation points Microsoft Vendor
2022-08-29T03:03:03.277+00:00

Hello,

You need to use File system helpers in MAUI to get the Stream from files on Windows platform.

Referring to this documentation, you could find the following content:

FileSystem.OpenAppPackageFileAsync
Files that were added to the project with the Build Action of MauiAsset can be opened with this method. .NET MAUI projects will process any file in the Resources\Raw folder as a MauiAsset.

Therefore, you need to add <MauiAsset Include="Resources\Images\**"/> in your project file at first, then you could use the following code to get Stream:

   // binaryFile = "Resources\\Images\\dotnet_bot.svg"
private async static Task<Stream> GetBinaryStream(string binaryFile)
{
using Stream fileStream = await FileSystem.Current.OpenAppPackageFileAsync(binaryFile);
return fileStream;
}


Best Regards,

Alec Liu.