Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
Resources/Images.xcassets/LaunchImage.launchimage
AppDelegate.cs reorganizing files into recipes folder Mar 7, 2018
FileSystemViewController.cs
Info.plist
README.md adding absolute links to recipes in metadata to make them clickable Mar 29, 2018
SaveDocuments.csproj
SaveDocuments.sln reorganizing files into recipes folder Mar 7, 2018

README.md

id title brief article
D6D866A3-95F9-9005-A018-A6A1345D5D5C
Save Documents
This recipe shows how to save a text file to the Documents folder.

Recipe

To save a string value to a text file

  1. Make sure you add a using statement for System.IO.
using System.IO;
  1. Determine the path for the **Documents** folder:
var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
  1. Construct a filename to save the document to:
var filename = Path.Combine (documents, "Write.txt");
  1. Write to the file:
File.WriteAllText(filename, "Write this text into a file!");

Additional Information

iTunes File Access

Users can access files in the Documents folder via iTunes if you add the following key to your Info.plist file:

<key>UIFileSharingEnabled</key>  <true />

When the device is plugged in to iTunes, the Documents folder is accessible for users to upload or download files (they can also download directories, but they cannot “browse” directories via the iTunes user interface).

Read the File

To read the same text file from the Documents folder:

  1. Determine the path for the Documents folder:
var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
  1. Construct the filename to read from:
var filename = Path.Combine (documents, "Write.txt");
  1. Read the file’s contents into a variable:
var text = File.ReadAllText(filename);