山本

导航

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

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

<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();
        }

posted on 2012-12-07 21:58  高级菜鸟  阅读(151)  评论(0编辑  收藏  举报