PathIO class
Provides helper methods for reading and writing a file using the absolute path or URI of the file.
Syntax
var pathIO = Windows.Storage.PathIO;
Attributes
- MarshalingBehaviorAttribute(Agile)
- StaticAttribute(Windows.Storage.IPathIOStatics, NTDDI_WIN8)
- ThreadingAttribute(Both)
- VersionAttribute(NTDDI_WIN8)
Members
The PathIO class has these types of members:
Methods
The PathIO class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.
| Method | Description |
|---|---|
| AppendLinesAsync(String, IIterable(String)) | Appends lines of text to the file at the specified path or Uniform Resource Identifier (URI). |
| AppendLinesAsync(String, IIterable(String), UnicodeEncoding) | Appends lines of text to the file at the specified path or Uniform Resource Identifier (URI) using the specified character encoding. |
| AppendTextAsync(String, String) | Appends text to the file at the specified path or Uniform Resource Identifier (URI). |
| AppendTextAsync(String, String, UnicodeEncoding) | Appends text to the file at the specified path or Uniform Resource Identifier (URI) using the specified character encoding. |
| ReadBufferAsync | Reads the contents of the file at the specified path or Uniform Resource Identifier (URI) and returns a buffer. |
| ReadLinesAsync(String) | Reads the contents of the file at the specified path or Uniform Resource Identifier (URI) and returns lines of text. |
| ReadLinesAsync(String, UnicodeEncoding) | Reads the contents of the file at the specified path or Uniform Resource Identifier (URI) using the specified character encoding and returns lines of text. |
| ReadTextAsync(String) | Reads the contents of the file at the specified path or Uniform Resource Identifier (URI) and returns text. |
| ReadTextAsync(String, UnicodeEncoding) | Reads the contents of the file at the specified path or Uniform Resource Identifier (URI) using the specified character encoding and returns text. |
| WriteBufferAsync | Writes data from a buffer to the file at the specified path or Uniform Resource Identifier (URI). |
| WriteBytesAsync | Writes a single byte of data to the file at the specified path or Uniform Resource Identifier (URI). |
| WriteLinesAsync(String, IIterable(String)) | Writes lines of text to the file at the specified path or Uniform Resource Identifier (URI). |
| WriteLinesAsync(String, IIterable(String), UnicodeEncoding) | Writes lines of text to the file at the specified path or Uniform Resource Identifier (URI) using the specified character encoding. |
| WriteTextAsync(String, String) | Writes text to the file at the specified path or Uniform Resource Identifier (URI). |
| WriteTextAsync(String, String, UnicodeEncoding) | Writes text to the file at the specified path or Uniform Resource Identifier (URI) using the specified character encoding. |
Remarks
This class is static and cannot be instantiated. Call the methods directly instead.
Note To read or write to a file using a path or URIs, you must have permission to access the file's location. To learn more about what locations your app has permission to access, see File access and permissions in Windows Store apps.
You can specify an app URIs to read or write files in app-specific locations like your app data folder ("ms-appdata://"). To learn more about app URIs, see How to reference content.
Examples
You can use writeTextAsync(filePathOrURI, contents) to write text to a file, like this:
if (file !== null) { Windows.Storage.PathIO.writeTextAsync(filePathOrURI, "Swift as a shadow").done(function () { // Perform additional tasks after file is written }, // Handle errors with an error function function (error) { // Handle errors encountered during write }); }
In the example, filePathOrURI is a local variable that contains a URI (like an app URI "ms-appdata://sampleFile.dat") or a file system path (like C:\examplepath\sampleFile.dat) for the file to read.
Although the writeTextAsync methods don't have a return value, you can still perform additional tasks after the text is written to the file, as the example shows.
You can use readTextAsync(filePathOrURI) to read text from a file, like this:
if (file !== null) { Windows.Storage.PathIO.readTextAsync(filePathOrURI).done(function (fileContent) { // Process content read from the file }, // Handle errors with an error function function (error) { // Handle errors encountered during read }); }
In the example, filePathOrURI is a local variable that contains a URI (like an app URI "ms-appdata://sampleFile.dat") or a file system path (like C:\examplepath\sampleFile.dat) for the file to read.
After readTextAsync completes, the fileContent variable gets the contents of the file as a text string. You can then process the contents as appropriate.
For more, related examples, see File Access sample and FileIO.
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps only] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps only] |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 5/16/2013
