- Add the file to your Xamarin.iOS project and ensure the
Build Action
is set to BundleResource. The sample code has a file called ReadMe.txt in the TestData folder.
- Load the file’s contents into a variable using
ReadAllText
. Notice the path that is passed to the method is relative to the project’s root -
var text = System.IO.File.ReadAllText("TestData/ReadMe.txt");
- Do something with the text, such as write to the Console or show in a
UITextView
:
Console.WriteLine(text); txtView.Text = text;
- Do something with the text, such as write to the Console or show in a
-
To save a string value to a text file
- Make sure you add a using statement for
System.IO
.
using System.IO;
- Determine the path for the **Documents** folder:
var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
- Construct a filename to save the document to:
var filename = Path.Combine (documents, "Write.txt");
- Write to the file:
File.WriteAllText(filename, "Write this text into a file!");
- Make sure you add a using statement for