WindowsRuntimeStorageExtensions.OpenStreamForWriteAsync Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Aşırı Yüklemeler
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. |
OpenStreamForWriteAsync(IStorageFile)
Önemli
Bu API, CLS uyumlu değildir.
Belirtilen dosyaya yazmak için bir akış alır.
public:
[System::Runtime::CompilerServices::Extension]
static System::Threading::Tasks::Task<System::IO::Stream ^> ^ OpenStreamForWriteAsync(Windows::Storage::IStorageFile ^ windowsRuntimeFile);
[System.CLSCompliant(false)]
public static System.Threading.Tasks.Task<System.IO.Stream> OpenStreamForWriteAsync (this Windows.Storage.IStorageFile windowsRuntimeFile);
[<System.CLSCompliant(false)>]
static member OpenStreamForWriteAsync : Windows.Storage.IStorageFile -> System.Threading.Tasks.Task<System.IO.Stream>
<Extension()>
Public Function OpenStreamForWriteAsync (windowsRuntimeFile As IStorageFile) As Task(Of Stream)
Parametreler
- windowsRuntimeFile
- IStorageFile
Yazacak Windows Çalışma Zamanı IStorageFile nesnesi.
Döndürülenler
Zaman uyumsuz yazma işlemini temsil eden görev.
- Öznitelikler
Özel durumlar
windowsRuntimeFile
, null
değeridir.
Dosya akış olarak açılamadı veya alınamadı.
Örnekler
Aşağıdaki örnekte, bir dosyanın Bir Windows Mağazası uygulamasında olarak Stream nasıl açılıp sınıfının bir örneğini kullanarak bu dosyaya nasıl yazılır gösterilmektedir 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)
{
StorageFile newFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("testfile3.txt");
using (StreamWriter writer = new StreamWriter(await newFile.OpenStreamForWriteAsync()))
{
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("testfile3.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)
Dim newFile As StorageFile = Await ApplicationData.Current.LocalFolder.CreateFileAsync("testfile4.txt")
Using writer As StreamWriter = New StreamWriter(Await newFile.OpenStreamForWriteAsync())
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("testfile4.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
Not
Visual Basic ve C# içinde, türündeki herhangi bir nesnede IStorageFileörnek yöntemi olarak bu yöntemi çağırabilirsiniz. Bu yöntemi çağırmak için örnek yöntemi sözdizimini kullandığınızda, ilk parametreyi yok sayın. Daha fazla bilgi için bkz . Uzantı Yöntemleri (Visual Basic) veya Uzantı Yöntemleri (C# Programlama Kılavuzu).
Şunlara uygulanır
OpenStreamForWriteAsync(IStorageFolder, String, CreationCollisionOption)
Önemli
Bu API, CLS uyumlu değildir.
Belirtilen üst klasördeki bir dosyaya yazmak için bir akış alır.
public:
[System::Runtime::CompilerServices::Extension]
static System::Threading::Tasks::Task<System::IO::Stream ^> ^ OpenStreamForWriteAsync(Windows::Storage::IStorageFolder ^ rootDirectory, System::String ^ relativePath, Windows::Storage::CreationCollisionOption creationCollisionOption);
[System.CLSCompliant(false)]
public static System.Threading.Tasks.Task<System.IO.Stream> OpenStreamForWriteAsync (this Windows.Storage.IStorageFolder rootDirectory, string relativePath, Windows.Storage.CreationCollisionOption creationCollisionOption);
[<System.CLSCompliant(false)>]
static member OpenStreamForWriteAsync : Windows.Storage.IStorageFolder * string * Windows.Storage.CreationCollisionOption -> System.Threading.Tasks.Task<System.IO.Stream>
<Extension()>
Public Function OpenStreamForWriteAsync (rootDirectory As IStorageFolder, relativePath As String, creationCollisionOption As CreationCollisionOption) As Task(Of Stream)
Parametreler
- rootDirectory
- IStorageFolder
Yazacak dosyayı içeren Windows Çalışma Zamanı IStorageFile nesnesi.
- relativePath
- String
Kök klasöre göre yazacak dosyanın yolu.
- creationCollisionOption
- CreationCollisionOption
Oluşturulacak dosyanın adı var olan bir dosyanın adıyla aynı olduğunda kullanılacak davranışı belirten Windows Çalışma Zamanı CreationCollisionOption numaralandırma değeri.
Döndürülenler
Zaman uyumsuz yazma işlemini temsil eden görev.
- Öznitelikler
Özel durumlar
rootDirectory
veya relativePath
şeklindedir null
.
relativePath
boş veya yalnızca boşluk karakterleri içeriyor.
Dosya akış olarak açılamadı veya alınamadı.
Örnekler
Aşağıdaki örnekte, bir dosyanın Bir Windows Mağazası uygulamasında olarak Stream nasıl açılıp sınıfının bir örneğini kullanarak bu dosyaya nasıl yazılır gösterilmektedir 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
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
Not
Visual Basic ve C# içinde, türündeki herhangi bir nesnede IStorageFolderörnek yöntemi olarak bu yöntemi çağırabilirsiniz. Bu yöntemi çağırmak için örnek yöntemi sözdizimini kullandığınızda, ilk parametreyi yok sayın. Daha fazla bilgi için bkz . Uzantı Yöntemleri (Visual Basic) veya Uzantı Yöntemleri (C# Programlama Kılavuzu).
Şunlara uygulanır
Geri Bildirim
https://aka.ms/ContentUserFeedback.
Çok yakında: 2024 boyunca, içerik için geri bildirim mekanizması olarak GitHub Sorunları’nı kullanımdan kaldıracak ve yeni bir geri bildirim sistemiyle değiştireceğiz. Daha fazla bilgi için bkz.Gönderin ve geri bildirimi görüntüleyin