WPF选择文件、文件夹和另存为对话框
一 WPF
1.1 选择文件对话框
OpenFileDialog类存在于PresentationFramework.dll程序集。
public string SelectFileWpf()
{
var openFileDialog = new Microsoft.Win32.OpenFileDialog()
{
Filter = "Text documents (.txt)|*.txt|All files (*.*)|*.*"
};
var result = openFileDialog.ShowDialog();
if (result == true)
{
return openFileDialog.FileName;
}
else
{
return null;
}
}
1.2选择文件夹
WPF提供了选择文件对话框,但并没有提供选择文件夹的对话框。
1.3另存为对话框
SaveFileDialog类位于PresentationFramework.dll 的Microsoft.Win32命名空间
public static string ChooseSaveFile(string title,string initFolder)
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.Title = title;
dlg.FileName = "User.txt"; // Default file name
dlg.DefaultExt = ".txt"; // Default file extension
dlg.Filter = "Text documents|*.txt"; // Filter files by extension
dlg.InitialDirectory = initFolder; // Process save file dialog box results
if (dlg.ShowDialog() == true)
{
return dlg.FileName;
}
else
{
return null;
}
}
二 WinForm
下面需要添加System.Windows.Forms.dll
2.1选择文件
1 public string SelectFile() //弹出一个选择文件的对话框
2 {
3 OpenFileDialog file = new OpenFileDialog();
4 file.ShowDialog();
5 return file.SafeFileName;
6 }
2.2选择文件夹
using System.Windows.Forms; FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
string outDir = folderBrowserDialog.SelectedPath;
}
参考:
WPF选择文件、文件夹和另存为对话框的更多相关文章
- WPF 选择电脑文件显示路径,弹出资源管理器,打开文件
选择文件,将路径显示在名为txbx的textbox上 // 在WPF中, OpenFileDialog位于Microsoft.Win32名称空间 Microsoft.Win32.OpenFileDia ...
- 在WPF中使用文件夹选择对话框
开发中有时会想实现"选择某个文件夹"的效果: 在WPF中,使用Microsoft.Win32.OpenFileDialog只能选择文件,FolderBrowserDialog只能用 ...
- WPF中使用文件浏览对话框的几种方式
原文:WPF中使用文件浏览对话框的几种方式 WPF本身并没有为我们提供文件浏览的控件, 也不能直接使用Forms中的控件,而文件浏览对话框又是我们最常用的控件之一. 下面是我实现的方式 方式1: 使用 ...
- java 弹出选择目录框(选择文件夹),获取选择的文件夹路径
java 弹出选择目录框(选择文件夹),获取选择的文件夹路径 java 弹出选择目录框(选择文件夹),获取选择的文件夹路径:int result = 0;File file = null;String ...
- VBA读取可选择文件夹下可选择txt文件内容
Sub OneTxt() '打开一个txt文件 Dim Filename As Variant, extLine&, mArr() As String Dim i%, j% ChDir Thi ...
- 用C#操作文件/文件夹(删除,复制,移动)
操作某一个文件/文件夹,需要一个文件的完整路径 一.使用File的静态方法进行文件操作 //使用file的静态方法进行复制 File.Copy(path, destpath); //使用File的静态 ...
- DOS批处理命令递归删除给定的文件(夹),兼VC工程清理小工具
使用dos批处理命令递归删除指定的文件(夹): (下面内容针对清理VC工程!自己按说明任意修改) 2014-06-10修改:删除前增加了[y,n]询问: echo off rem 递归删除当前文件下指 ...
- input文件上传(上传单个文件/多选文件/文件夹、拖拽上传、分片上传)
//上传单个/多个文件 <input title="点击选择文件" id="h5Input1" multiple="" accept= ...
- MFC_CFileDialog_选择单一文件
场景 选择单一文件 技术点 CFileDialog CFileDialog::CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, ...
随机推荐
- TZOJ 4007 The Siruseri Sports Stadium(区间贪心)
描述 The bustling town of Siruseri has just one sports stadium. There are a number of schools, college ...
- Python threading 单线程 timer重复调用函数
项目中需要使用定时器,每次都使用构造器函数调用: timer = threading.Timer(timerFlag, upload_position) timer.start() 打印线程后发现,每 ...
- 硬盘的 read0 read 1
Read 0:组建的时候必须2块容量相同的硬盘,每个程序的数据以一定的大小分别写在两个硬盘里,读的时候从两个硬盘里一起读,这种阵列方式理论上硬盘的读写速度是一块硬盘的2倍,实际应用中大约速度比一块硬盘 ...
- Laravel 上使用 phpexcel的两种方式
原创 2017年06月24日 20:24:31 1229 文章采集与网上 方式1.使用原生的phpexcel , http://blog.csdn.net/CSwfe/article/details/ ...
- Spring+SpringMVC+mybatis+Quartz整合
Quartz与SpringMVC的整合 简介 Quartz是一个完全由java编写的开源作业调度框架,为在Java应用程序中进行作业调度提供了简单却强大的机制.Quartz允许开发人员根据时间间隔来调 ...
- PTA第一次作业和第二次作业
PTA的第一次作业第一题: #include <stdio.h> int main (void) { int grade,i,N ,a=0,b=0,c=0,d=0,e=0; printf( ...
- servlet-cookie
/** * Cookie学习; * 作用:解决了发送的不同请求的数据共享问题 * 使用: * 1.Cookie的创建和存储 * ...
- js如何实现网站title的滚动效果
var text=document.title;//获得页面的标题 var timerID;//定时器 function newtext() { ...
- 2018.10.05 NOIP模拟 阶乘(简单数论)
传送门 签到题. 直接把所有数先质因数分解. 同时统计每一个在阶乘中会出现的质数出现的最少次数. 然后对于每一个这样的质数,我们求出满足其出现质数的m的最小值,然后求出所有m的最大值. 求m的时候可以 ...
- yii2 HTML组手
1.样式和脚本 1.1 Yii 提供两个方法用于生成包含内联样式和脚本代码的标签. <?= Html::style('.danger { color: #f00; }') ?> Gives ...