如何编写用于浏览文件夹/文件的代码? [英] How to write a code for browse folder/file?

查看:227
本文介绍了如何编写用于浏览文件夹/文件的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦单击按钮,它应该允许用户从文件中选择项目.
如何在C#中创建它?

用户需要在此处从文件中选择图片.
请帮助我.

Once the button is clicked, it should allow the user to select items from files.
How can I create it in C#?

here the user needs to select pictures from the files.
Please help me.

推荐答案

这取决于您要查找的内容:如果它是供用户打开的文件:

It depends what you are trying to find: If it is a file for the user to open:

OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
   {
   ...
   }

如果它是文件夹:

If it is a folder:

FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
   {
   ...
   }

如果它是文件中的信息,我们将需要更多信息!

If it is information within a file, the we would need lots more information!


由于 OriginalGriff 为您提供了需要使用OpenFileDialog的解决方案使用对话框访问文件.
我只是在扩展使用OpenFileDialog
的地方 如果需要访问多个文件,则需要使用OpenFileDialog类的Multiselect属性.正如您提到的,用户需要使用OpenFileDialog选择图片,您可以为此使用Filter属性

As OriginalGriff gives you a solution that you need use OpenFileDialog to access file by using a Dialog Box.
I am just extending some point of Using OpenFileDialog
if you need to access more than one File you need to use Multiselect property of OpenFileDialog Class. as you mentioned user need to select Pictures using OpenFileDialog you can use Filter property for that
as
OpenFiledialog.Filter = "Image Files|*.jpg;*.gif;*.bmp;*.png;*.jpeg|All Files|*.*"


有关更多详细信息,请参见有-[使用OpenFileDialog] [


and for more details have a look there-[Using OpenFileDialog][^]


这篇关于如何编写用于浏览文件夹/文件的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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