WindowsRuntimeStorageExtensions Sınıf

Tanım

Windows Store uygulamaları geliştirirken Windows Çalışma Zamanı ve IStorageFolder arabirimleri için IStorageFile uzantı yöntemlerini içerir.

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
Devralma
WindowsRuntimeStorageExtensions
Öznitelikler

Örnekler

Aşağıdaki örnekte, uygulama verilerinde bir dosyanın bir Windows Store uygulamasında olduğu gibi Stream nasıl açılıp sınıfın bir örneğini kullanarak bu dosyaya nasıl yazılır gösterilmektedirStreamWriter. Daha sonra sınıfının bir örneğini StreamReader kullanarak dosyanın içeriğini okur.

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

Sonraki örnekte, önceki örnekle ilişkili XAML kodu gösterilmektedir.

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

Açıklamalar

Bu uzantı yöntemleri yalnızca Windows Store uygulamaları geliştirirken kullanılabilir. Yöntemler, Windows Store uygulamalarında okumak veya yazmak için dosyaları açmanın kolay yollarını sağlar. Sınıfının bir örneğini WindowsRuntimeStorageExtensions oluşturmazsınız; bunun yerine ve IStorageFolder arabirimlerinin IStorageFile örneklerinden bu yöntemleri kullanırsınız.

sınıfı WindowsRuntimeStorageExtensions , okuma veya yazma için genişleten IStorageFile iki yöntem içerir:

WindowsRuntimeStorageExtensions sınıfı, okuma ve yazma için genişleten IStorageFolder iki yöntem içerir:

Yöntemler

CreateSafeFileHandle(IStorageFile, FileAccess, FileShare, FileOptions)

Geçerli depolama dosyası örneği için güvenli bir dosya tanıtıcısı oluşturur.

CreateSafeFileHandle(IStorageFolder, String, FileMode)

Geçerli depolama klasörü örneğindeki bir dosya için güvenli bir dosya tanıtıcısı oluşturur.

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

Geçerli depolama klasörü örneğindeki bir dosya için güvenli bir dosya tanıtıcısı oluşturur.

OpenStreamForReadAsync(IStorageFile)

Belirtilen bir dosyadan okumak için bir akış alır.

OpenStreamForReadAsync(IStorageFolder, String)

Belirtilen üst klasördeki bir dosyadan okumak için bir akış alır.

OpenStreamForWriteAsync(IStorageFile)

Belirtilen dosyaya yazmak için bir akış alır.

OpenStreamForWriteAsync(IStorageFolder, String, CreationCollisionOption)

Belirtilen üst klasördeki bir dosyaya yazmak için bir akış alır.

Şunlara uygulanır