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:
-
Create a file in the Documents library
Uses one of the StorageFolder . CreateFileAsync methods to create the file.
-
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.
-
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.
-
Write and read a file using a stream
Uses the following API to write and read the file using a stream.
- StorageFile . OpenTransactedWriteAsync method
- DataWriter class
- DataReader class
For a walkthrough of this task, see Quickstart: reading and writing a file.
-
Display file properties
Uses the StorageFile . GetBasicPropertiesAsync method and the StorageFile. Properties property to get the properties of the file.
-
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.
-
Copy a file
Uses one of the StorageFile . CopyAsync methods to copy the file.
-
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 namespaceOperating system requirements
Client | |
---|---|
Server |
Build the sample
- Start Visual Studio 2012 and select File > Open > Project/Solution.
- 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.
- 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.