WindowsRuntimeStorageExtensions クラス

定義

Windows ストア アプリ開発時の Windows ランタイム内の IStorageFile インターフェイスおよび IStorageFolder インターフェイス用の拡張メソッドを格納します。

public ref class WindowsRuntimeStorageExtensions abstract sealed
public static class WindowsRuntimeStorageExtensions
[System.Security.SecurityCritical]
public static class WindowsRuntimeStorageExtensions
type WindowsRuntimeStorageExtensions = class
[<System.Security.SecurityCritical>]
type WindowsRuntimeStorageExtensions = class
Public Module WindowsRuntimeStorageExtensions
継承
WindowsRuntimeStorageExtensions
属性

次の例は、アプリケーション データ内のファイルを Windows ストア アプリで a としてStream開き、クラスのインスタンスを使用してファイルに書き込む方法をStreamWriter示しています。 次に、クラスのインスタンスを使用してファイルの内容を StreamReader 読み取ります。

using System;
using System.IO;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace ExampleApplication
{
    public sealed partial class BlankPage : Page
    {
        public BlankPage()
        {
            this.InitializeComponent();
        }

        private async void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            using (StreamWriter writer =
                new StreamWriter(await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(
                "testfile.txt",  CreationCollisionOption.OpenIfExists)))
            {
                await writer.WriteLineAsync("new entry");
                await writer.WriteLineAsync(UserText.Text);
            }
        }

        private async void VerifyButton_Click(object sender, RoutedEventArgs e)
        {
            StorageFile openedFile = await ApplicationData.Current.LocalFolder.GetFileAsync("testfile.txt");
            using (StreamReader reader = new StreamReader(await openedFile.OpenStreamForReadAsync()))
            {
                Results.Text = await reader.ReadToEndAsync();
            }
        }
    }
}
Imports System.IO
Imports Windows.Storage

NotInheritable Public Class BlankPage
    Inherits Page

    Private Async Sub CreateButton_Click(sender As Object, e As RoutedEventArgs)
        Using writer As StreamWriter =
               New StreamWriter(Await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(
               "testfile.txt", CreationCollisionOption.OpenIfExists))
            Await writer.WriteLineAsync("new entry")
            Await writer.WriteLineAsync(UserText.Text)
        End Using
    End Sub

    Private Async Sub VerifyButton_Click(sender As Object, e As RoutedEventArgs)
        Dim openedFile As StorageFile = Await ApplicationData.Current.LocalFolder.GetFileAsync("testfile.txt")
        Using reader As StreamReader = New StreamReader(Await openedFile.OpenStreamForReadAsync())
            Results.Text = Await reader.ReadToEndAsync()
        End Using
    End Sub
End Class

次の例は、前の例に関連付けられている XAML コードを示しています。

<Page
    x:Class="ExampleApplication.BlankPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ExampleApplication"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <StackPanel Background="{StaticResource ApplicationPageBackgroundBrush}" VerticalAlignment="Center" HorizontalAlignment="Center">
        <TextBlock Text="Provide text to write to file:"></TextBlock>
        <TextBox Name="UserText" Width="400"></TextBox>
        <Button Name="CreateButton" Content="Create File" Click="CreateButton_Click"></Button>
        <Button Name="VerifyButton" Content="Verify Contents" Click="VerifyButton_Click"></Button>
        <TextBlock Name="Results"></TextBlock>
    </StackPanel>
</Page>

注釈

これらの拡張メソッドは、Windowsストア アプリを開発する場合にのみ使用できます。 このメソッドは、Windows ストア アプリでファイルを読み取りまたは書き込みするための便利な方法を提供します。 クラスのWindowsRuntimeStorageExtensionsインスタンスは作成しません。代わりに、これらのメソッドをインターフェイスのIStorageFileIStorageFolderインスタンスから使用します。

この WindowsRuntimeStorageExtensions クラスには、読み取りまたは書き込みのために拡張 IStorageFile される 2 つのメソッドが含まれています。

WindowsRuntimeStorageExtensions クラスには、読み取りと書き込みのために拡張 IStorageFolder される 2 つのメソッドが含まれています。

メソッド

CreateSafeFileHandle(IStorageFile, FileAccess, FileShare, FileOptions)

現在のストレージ ファイル インスタンスのセーフ ファイル ハンドルを作成します。

CreateSafeFileHandle(IStorageFolder, String, FileMode)

現在のストレージ フォルダー インスタンス内にあるファイルのセーフ ファイル ハンドルを作成します。

CreateSafeFileHandle(IStorageFolder, String, FileMode, FileAccess, FileShare, FileOptions)

現在のストレージ フォルダー インスタンス内にあるファイルのセーフ ファイル ハンドルを作成します。

OpenStreamForReadAsync(IStorageFile)

指定したファイルから読み取るストリームを取得します。

OpenStreamForReadAsync(IStorageFolder, String)

指定された親フォルダーのファイルから読み取るストリームを取得します。

OpenStreamForWriteAsync(IStorageFile)

指定したファイルへ書き込むストリームを取得します。

OpenStreamForWriteAsync(IStorageFolder, String, CreationCollisionOption)

指定された親フォルダーのファイルへ書き込むストリームを取得します。

適用対象