PathIO PathIO PathIO PathIO PathIO Class

Definition

Provides helper methods for reading and writing a file using the absolute path or Uniform Resource Identifier (URI) of the file.

public : static class PathIO
static struct winrt::Windows::Storage::PathIO
public static class PathIO
Public Shared Class PathIO
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

You can use writeTextAsync(filePathOrURI, contents) to write text to a file. 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.


try
{
    if (file != null)
    {
        await PathIO.WriteTextAsync(filePathOrURI, "Swift as a shadow");
    }
}
// Handle errors with catch blocks
catch (FileNotFoundException)
{
    // For example, handle file not found
}

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
    });
}

You can use readTextAsync(filePathOrURI) to read text from a file. After readTextAsync completes, the fileContent variable gets the contents of the file as a text string. You can then process the contents as appropriate.

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
    });
}
try
{
    if (file != null)
    {
        string fileContent = await PathIO.ReadTextAsync(filePathOrURI);
    }
}
// Handle errors with catch blocks
catch (FileNotFoundException)
{
    // For example, handle file not found
}

For more, related examples, see File Access sample and FileIO.

Remarks

To read or write to a file using a path or Uniform Resource Identifier (URI), 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 permissions.

You can specify an app Uniform Resource Identifier (URI) to read or write files in app-specific locations like your app data folder ("ms-appdata://"). To learn more about app Uniform Resource Identifier (URI), see How to reference content.

Methods

AppendLinesAsync(String, IIterable<String>) AppendLinesAsync(String, IIterable<String>) AppendLinesAsync(String, IIterable<String>) AppendLinesAsync(String, IIterable<String>) 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) AppendLinesAsync(String, IIterable<String>, UnicodeEncoding) AppendLinesAsync(String, IIterable<String>, UnicodeEncoding) AppendLinesAsync(String, IIterable<String>, UnicodeEncoding) 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) AppendTextAsync(String, String) AppendTextAsync(String, String) AppendTextAsync(String, String) AppendTextAsync(String, String)

Appends text to the file at the specified path or Uniform Resource Identifier (URI).

AppendTextAsync(String, String, UnicodeEncoding) AppendTextAsync(String, String, UnicodeEncoding) AppendTextAsync(String, String, UnicodeEncoding) AppendTextAsync(String, String, UnicodeEncoding) AppendTextAsync(String, String, UnicodeEncoding)

Appends text to the file at the specified path or Uniform Resource Identifier (URI) using the specified character encoding.

ReadBufferAsync(String) ReadBufferAsync(String) ReadBufferAsync(String) ReadBufferAsync(String) ReadBufferAsync(String)

Reads the contents of the file at the specified path or Uniform Resource Identifier (URI) and returns a buffer.

ReadLinesAsync(String) ReadLinesAsync(String) ReadLinesAsync(String) ReadLinesAsync(String) 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) ReadLinesAsync(String, UnicodeEncoding) ReadLinesAsync(String, UnicodeEncoding) ReadLinesAsync(String, UnicodeEncoding) 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) ReadTextAsync(String) ReadTextAsync(String) ReadTextAsync(String) ReadTextAsync(String)

Reads the contents of the file at the specified path or Uniform Resource Identifier (URI) and returns text.

ReadTextAsync(String, UnicodeEncoding) ReadTextAsync(String, UnicodeEncoding) ReadTextAsync(String, UnicodeEncoding) ReadTextAsync(String, UnicodeEncoding) 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(String, IBuffer) WriteBufferAsync(String, IBuffer) WriteBufferAsync(String, IBuffer) WriteBufferAsync(String, IBuffer) WriteBufferAsync(String, IBuffer)

Writes data from a buffer to the file at the specified path or Uniform Resource Identifier (URI).

WriteBytesAsync(String, Byte[]) WriteBytesAsync(String, Byte[]) WriteBytesAsync(String, Byte[]) WriteBytesAsync(String, Byte[]) WriteBytesAsync(String, Byte[])

Writes a single byte of data to the file at the specified path or Uniform Resource Identifier (URI).

WriteLinesAsync(String, IIterable<String>) WriteLinesAsync(String, IIterable<String>) WriteLinesAsync(String, IIterable<String>) WriteLinesAsync(String, IIterable<String>) 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) WriteLinesAsync(String, IIterable<String>, UnicodeEncoding) WriteLinesAsync(String, IIterable<String>, UnicodeEncoding) WriteLinesAsync(String, IIterable<String>, UnicodeEncoding) 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) WriteTextAsync(String, String) WriteTextAsync(String, String) WriteTextAsync(String, String) WriteTextAsync(String, String)

Writes text to the file at the specified path or Uniform Resource Identifier (URI).

WriteTextAsync(String, String, UnicodeEncoding) WriteTextAsync(String, String, UnicodeEncoding) WriteTextAsync(String, String, UnicodeEncoding) WriteTextAsync(String, String, UnicodeEncoding) WriteTextAsync(String, String, UnicodeEncoding)

Writes text to the file at the specified path or Uniform Resource Identifier (URI) using the specified character encoding.

See Also