win8中的文件选取问题解决方法 .

it2022-05-20  68

---------前台代码

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">        <Button Name="btnRead" Content="读取" HorizontalAlignment="Left" Margin="425,131,0,0" VerticalAlignment="Top" Click="btnRead_Click_1"/>        <Button Name="btnWrite" Content="写入" HorizontalAlignment="Left" Margin="725,131,0,0" VerticalAlignment="Top" Click="btnWrite_Click_1"/>        <Button Name="btnCreate" Content="创建" HorizontalAlignment="Left" Margin="425,233,0,0" VerticalAlignment="Top" Click="btnCreate_Click_1"/>

    </Grid>

---------后台代码

 private async void btnWrite_Click_1(object sender, RoutedEventArgs e)        {            StorageFolder document = Windows.Storage.KnownFolders.DocumentsLibrary;            StorageFile file = await document.GetFileAsync("旅游计划.txt");            await FileIO.WriteTextAsync(file, "今天的工作计划");            MessageDialog mes = new MessageDialog("写入成功");            await mes.ShowAsync();        }

        private async void btnCreate_Click_1(object sender, RoutedEventArgs e)        {                        StorageFolder document= Windows.Storage.KnownFolders.DocumentsLibrary;            StorageFile file= await document.CreateFileAsync("旅游计划.txt",CreationCollisionOption.ReplaceExisting);            MessageDialog mes = new MessageDialog(file.Path);            await mes.ShowAsync();        }

转载于:https://www.cnblogs.com/qzc900809/archive/2012/12/07/2807937.html


最新回复(0)