In this recipe, we will learn how to create files on the filesystem of iOS devices.
Create a new iPhone Single View Application project in MonoDevelop. Name it FileCreationApp
. Open the FileCreationAppViewController.xib
file, and add a UILabel
and a UIButton
on its view.
Enter the following code in the FileCreationAppViewController
class:
public override void ViewDidLoad(){ string filePath = Path.Combine (Environment.GetFolderPath(Environment.SpecialFolder.Personal), "MyFile.txt"); using (StreamWriter sw = new StreamWriter (filePath)){ sw.WriteLine ("Some text in file!"); } this.btnShow.TouchUpInside += delegate { using (StreamReader sr = new StreamReader (filePath)){ this.labelMessage.Text = sr.ReadToEnd (); } } };