<metro>新建文件
2012-11-02 14:40
120 查看
首先,我们用vs2012来选择Blank App模板,再选好Button和BlockText控件,在Button中找到Click事件,点击进去。
其次,在Click事件中,用FileSavePicker类来New一个实例savePicker。 用实例savePicker来调用SuggestedStartLocation带确定起始位置,用FileTypeChoices来确定好要建文件类型,用DefaultFileExtension来确定默认类型,用SuggestedFileName来确定文件名。
接着,用StorageFile类来新建一个实例,用来等待异步创建文件。然后创建好的文件名输出。
最后,按F5。
在Click事件中的代码是:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> <Button x:Name="files_btn" Content="FileSavePicker" HorizontalAlignment="Left" Margin="514,79,0,0" VerticalAlignment="Top" Click="Files_Click"/> <TextBlock x:Name="fOutput" HorizontalAlignment="Left" Height="207" Margin="90,241,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="552"/> </Grid>
其次,在Click事件中,用FileSavePicker类来New一个实例savePicker。 用实例savePicker来调用SuggestedStartLocation带确定起始位置,用FileTypeChoices来确定好要建文件类型,用DefaultFileExtension来确定默认类型,用SuggestedFileName来确定文件名。
接着,用StorageFile类来新建一个实例,用来等待异步创建文件。然后创建好的文件名输出。
最后,按F5。
在Click事件中的代码是:
private async void Files_Click(object sender, RoutedEventArgs e) { FileSavePicker savePicker = new FileSavePicker(); savePicker.SuggestedStartLocation = PickerLocationId.Desktop; savePicker.FileTypeChoices.Add("Microsoft Word Document", new List<string>() { ".docx", ".doc" }); savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" }); savePicker.DefaultFileExtension = ".docx"; savePicker.SuggestedFileName = "New Document"; StorageFile savedItem = await savePicker.PickSaveFileAsync(); if (null != savedItem) { fOutput.Text = savedItem.Name; } else { fOutput.Text = "End"; } }
相关文章推荐
- <metro>Application Data
- <9>python学习笔记——文件操作
- <数据结构 课程设计> 文件目录结构显示(Java 版)
- Android so文件进阶 <一>
- spring配置文件中的<value></value>
- <VirtualHost *:80>配置文件
- spring配置文件中的<context:annotation-config/>
- <context-param>与<init-param>的区别与作用含与Spring整合时的文件配置
- <climits>头文件使用方法
- <mvc:annotation-driven/>在配置文件不能解析原因
- <hadoop>文件流
- <文本文档和pdf文件互相转化>入门练习
- 在Android中,WebView中的<file>标签不能上传文件的解析
- Spring配置文件中使用ref local与ref bean的区别. 在ApplicationResources.properties文件中,使用<ref bean>与<ref local>方法如下
- <转>找不到文件 ' Microsoft.Windows.CommonLanguageRuntime, Version = 2.0.50727.0 '
- <归档> object-c把数据写入到文件中
- <Android> 文件夹和文件操作
- <nginx + php> 修改配置文件php.ini不生效
- <Linux内核源码>文件系统VFS内核4.0.4版本基本概念源码
- 用备份控制文件做不完全恢复下的完全恢复(数据文件备份<旧>--新建表空间--控制文件备份<次新>--日志归档文件<新>)