WPF的文件选择与保存
2016-03-01 10:32
363 查看
1.引用Windows.Form
2.打开文件
System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "(*.mdb)|*.mdb"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //此处做你想做的事 this.txt_datasource.Text = openFileDialog1.FileName; }
3.保存文件
System.Windows.Forms.SaveFileDialog saveDg = new System.Windows.Forms.SaveFileDialog(); saveDg.Filter = "(*.xls)|*.xls|(*.xlsx)|*.xlsx"; saveDg.FileName = tableName+DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss")+""; saveDg.AddExtension = true; saveDg.RestoreDirectory = true; if (saveDg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //此处做你想做的事 string filePath = saveDg.FileName; }
4.文件格式过滤
// // 摘要: // 获取或设置当前文件名筛选器字符串,该字符串决定对话框的“另存为文件类型”或“文件类型”框中出现的选择内容。 // // 返回结果: // 对话框中可用的文件筛选选项。 // // 异常: // T:System.ArgumentException: // Filter 格式无效。 [DefaultValue("")] [Localizable(true)] [SRCategoryAttribute("CatBehavior")] [SRDescriptionAttribute("FDfilterDescr")] public string Filter { get; set; }
相关文章推荐
- Python字符串的格式化
- Mysql event学习
- Codeforces Round #340 (Div. 2)C. Watering Flowers
- Android轻松画出触摸轨迹
- linux开机自动启动网络
- YUV数据格式
- 【程序员的爱情】彼岸花开谁又种下了执念
- 拯救无法启动的虚拟机文件.vmdk中的数据
- Eclipse配置Tomcat
- [BZOJ4199] [Noi2015]品酒大会
- js控制图片上传预览,使用三方插件+名称显示和控件非display:none隐藏
- 【HDU 5115】Dire Wolf
- 分布式session有以下几种方案
- Sql REVERSE 翻转字符串
- 敏捷开发
- eclipse设置Package Explorer的显示
- 维基百科开发知识搜索引擎Knowledge Engine
- Gt9xxxx系列------如何确定config档
- 第四届_翻硬币
- ActiveX控件安全初始化之一:实现ISafeObject接口(转)