Search This Blog

Thursday 17 June 2021

How to read local file in Xamarin Forms

How to read the local file in Xamarin Forms

Add text/HTML/JSON file in your Xamarin Form Project. Then change build action to Embedded Resource

Write the following code to access the file.

var assembly = typeof(AnyContentPageName).GetTypeInfo().Assembly;
Stream stream = assembly.GetManifestResourceStream("TestFile.json");
string jsonContent = string.Empty;
using (var reader = new System.IO.StreamReader(stream))
{
     jsonContent = reader.ReadToEnd();
}


No comments:

Post a Comment

Popular Posts