This sample shows how to create, read, write, copy and delete a file, how to retrieve file properties, and how to track a file or folder so that your app can access it again. This sample uses Windows.Storage and Windows.Storage.AccessCache API.

The sample demonstrates these tasks:

  1. Create a file in the Documents library

    Uses one of the StorageFolder . CreateFileAsync methods to create the file.

  2. Write and read text in a file

    Uses the FileIO . WriteTextAsync and FileIO. ReadTextAsync methods to write and read the file. For a walkthrough of this task, see Quickstart: reading and writing a file.

  3. Write and read bytes in a file

    Uses the FileIO . WriteBufferAsync and FileIO. ReadBufferAsync methods to write and read the file. For a walkthrough of this task, see Quickstart: reading and writing a file.

  4. Write and read a file using a stream

    Uses the following API to write and read the file using a stream.

    For a walkthrough of this task, see Quickstart: reading and writing a file.

  5. Display file properties

    Uses the StorageFile . GetBasicPropertiesAsync method and the StorageFile. Properties property to get the properties of the file.

  6. Track a file or folder so that you can access it later (persisting access)

    Uses the StorageApplicationPermissions . FutureAccessList and StorageApplicationPermissions. MostRecentlyUsedList properties to remember a file or folder so that it can be accessed later.

    For a walkthrough of this task, see How to track recently used files and folders.

  7. Copy a file

    Uses one of the StorageFile . CopyAsync methods to copy the file.

  8. Delete a file

    Uses one of the StorageFile . DeleteAsync methods to delete the file.

Note  If you want to learn about accessing files using a file picker, see Quickstart: Accessing files with file pickers.

To obtain an evaluation copy of Windows 8, go to Windows 8.

To obtain an evaluation copy of Microsoft Visual Studio 2012, go to Visual Studio 2012.

Related topics

Windows 8 app samples
Related samples
File picker sample
Folder enumeration sample
Programmatic file search sample
File and folder thumbnail sample

Related technologies

Windows.Storage namespace , Windows.Storage.AccessCache namespace , Windows.Storage.FileProperties , Windows.Storage.Streams namespace

Operating system requirements

Client
Windows 8
Server
Windows Server 2012

Build the sample

  1. Start Visual Studio 2012 and select File > Open > Project/Solution.
  2. Go to the directory in which you unzipped the sample. Go to the directory named for the sample, and double-click the Microsoft Visual Studio Solution (.sln) file.
  3. Press F6 or use Build > Build Solution to build the sample.

Run the sample

To debug the app and then run it, press F5 or use Debug > Start Debugging. To run the app without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.