So i've had this problem for a bit
I am opening my txt file to text and it only will open on IOS not Android. It just shows an error when i try to open Android.
I put the txt file in the Resource Folder for both IOS and Android but Android won't open it still.
Heres the code for the filepaths:
string filePathq = "questions.txt"; List<string> questions = File.ReadAllLines(filePathq).ToList();
If you could help me with this it would be greatly appreciated
To read txt file on xamarin cross platform, you could add the file to the shared project. Then set the Build Action to EmbeddedResource, load the file as resources with the following code on each platform.
var assembly = IntrospectionExtensions.GetTypeInfo(typeof(CurrentClass)).Assembly; Stream stream = assembly.GetManifestResourceStream("ProjectName.FileName.txt"); string text = ""; using (var reader = new System.IO.StreamReader(stream)) { text = reader.ReadToEnd(); }
Answers
To read txt file on xamarin cross platform, you could add the file to the shared project. Then set the Build Action to EmbeddedResource, load the file as resources with the following code on each platform.
Tutorial:
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/data/files?tabs=windows#loading-files-embedded-as-resources
But is this when accessing file from inside the library project. Not from the forms project?
CurrentClass
has to be a class inside the library project. Missed that