Created
April 15, 2012 04:38
-
-
Save biac/2390062 to your computer and use it in GitHub Desktop.
Demo1Page.SaveTxtButton_Click_1()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async void SaveTxtButton_Click_1(object sender, RoutedEventArgs e) | |
{ | |
var thisButton = sender as Button; | |
thisButton.IsEnabled = false; | |
// FileSavePicker を用意する | |
var picker = new FileSavePicker (); | |
picker.CommitButtonText = "テキストファイルを保存する"; | |
picker.DefaultFileExtension = ".txt"; | |
picker.FileTypeChoices.Add("TEXT", new string[]{".txt", ".csv"}); | |
picker.FileTypeChoices.Add("C# SRC", new string[] { ".cs", ".xaml" }); | |
picker.SuggestedStartLocation = PickerLocationId.Desktop; | |
picker.SuggestedFileName = "test.txt"; | |
// FileSavePicker を出して、ファイルを指定してもらう 【非同期!】 | |
StorageFile file = await picker.PickSaveFileAsync(); | |
if (file != null) { | |
using(Stream s = await file.OpenStreamForWriteAsync()) // Stream を作る 【非同期!】 | |
using(StreamWriter w = new StreamWriter(s, System.Text.Encoding.UTF8)) // Stream から StreamWriter を作る | |
await w.WriteAsync(this.TextArea.Text); // StreamWriter で書き込む 【非同期!】 | |
} | |
thisButton.IsEnabled = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment