C#,FolderBrowserDialog显示文件夹中的文件并选择一个文件 [英] C#, FolderBrowserDialog show files in a folder and select a file

查看:1340
本文介绍了C#,FolderBrowserDialog显示文件夹中的文件并选择一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我需要给该功能选择文件夹浏览器之类的组件中显示的文件夹中的文件.但是Windows默认文件夹浏览器仅允许选择文件夹,而不能选择文件夹中的文件.我怎样才能做到这一点.

在此先谢谢您.

Hi All,

I need to give the functionality select a file in a folder shown in component like folder browser. But windows default folder browser only allows to select folder, not the files in a folder. How can I do this.

Thanks in Advance.

推荐答案

FolderBrowserDialog纯粹是用于选择课程文件夹.

您正在寻找OpenFileDialog.

一个小例子:

FolderBrowserDialog is purely ment for Selecting folders ofcourse.

You are looking for OpenFileDialog.

A little example:

OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "PDF Files|*.pdf";

if (openFileDialog.ShowDialog() == DialogResult.OK)
{
   string filePath = openFileDialog.FileName;
}



现在,文件路径字符串包含所选文件的完整路径,您可以在上面放开自己的代码:)

祝你好运!



the filepath string now contains the full path to the file you have selected and you can let your own code loose upon it :)

Good luck!


这篇关于C#,FolderBrowserDialog显示文件夹中的文件并选择一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆