XAML (tasarım kısmı): <!--ContentPanel - place additional content here--> <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0"> <TextBox Name="textBox1" HorizontalAlignment="Left" Height="72" Margin="0,22,0,0" TextWrapping="Wrap" Text="Enter text here." VerticalAlignment="Top" Width="456"/> <Button Name='btnWrite' Content="Write" HorizontalAlignment="Left" Margin="10,94,0,0" VerticalAlignment="Top" Width="156" Click="btnWrite_Click"/> <TextBlock Name="textBlock1" HorizontalAlignment="Left" Margin="10,293,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="61" Width="436"/> <Button Name="btnRead" Content="Read" HorizontalAlignment="Left" Margin="10,374,0,0" VerticalAlignment="Top" Width="156" IsEnabled="False" Click="btnRead_Click"/> </Grid>
Klasör yaratmak ve yratılan klasöre dosya oluşturma: private async void btnWrite_Click(object sender, RoutedEventArgs e)
{
await WriteToFile();
// Update UI.
this.btnWrite.IsEnabled = false;
this.btnRead.IsEnabled = true;
}
private async Task WriteToFile()
{
// Get the text data from the textbox.
byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(this.textBox1.Text.ToCharArray());
// Get the local folder.
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
// Create a new folder name DataFolder.
var dataFolder = await local.CreateFolderAsync("DataFolder",
CreationCollisionOption.OpenIfExists);
// Create a new file named DataFile.txt.
var file = await dataFolder.CreateFileAsync("DataFile.txt",
CreationCollisionOption.ReplaceExisting);
// Write the data from the textbox.
using (var s = await file.OpenStreamForWriteAsync())
{
s.Write(fileBytes, 0, fileBytes.Length);
}
}
Diskten dosya okumak: private async void btnRead_Click(object sender, RoutedEventArgs e)
{
await ReadFile();
// Update UI.
this.btnWrite.IsEnabled = true;
this.btnRead.IsEnabled = false;
}
private async Task ReadFile()
{
// Get the local folder.
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
if (local != null)
{
// Get the DataFolder folder.
var dataFolder = await local.GetFolderAsync("DataFolder");
// Get the file.
var file = await dataFolder.OpenStreamForReadAsync("DataFile.txt");
// Read the data.
using (StreamReader streamReader = new StreamReader(file))
{
this.textBlock1.Text = streamReader.ReadToEnd();
}
}
}
------------- http://www.kasatakip.com - Kasa Takip | http://www.caritakip.com - Cari Takip | http://www.evraktakip.com - Evrak Takip | http://www.etasqlmobil.com - ETA SQL Mobil
|