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)
{
// Read the source file
using Stream fileStream = await FileSystem.Current.OpenAppPackageFileAsync(binaryFile);
return fileStream;
}
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.