Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

PathIO class

Applies to Windows and Windows Phone

Provides helper methods for reading and writing a file using the absolute path or URI of the file.

Syntax

Public NotInheritable Class PathIO

Attributes

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]

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.

MethodDescription
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:

No code example is currently available or this language may not be supported.

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:

No code example is currently available or this language may not be supported.

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]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.winmd

See also

File Access sample
FileIO

 

 

Show:
© 2014 Microsoft