在下拉菜单中选择.doc或.rtf文件的选项 [英] option for selcting .doc or .rtf file in dropdown
本文介绍了在下拉菜单中选择.doc或.rtf文件的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的代码中,我得到了显示在列表框中的文件名,但是我需要选择.doc或.rtf的选项,方法是通过选择要在文本框中显示的选定文件格式在文本框中的下拉列表中. .......
here in the below coding i got the filenames displayed in the listbox, but i need the option for selecting .doc or .rtf which is to in dropdown in text box by selecting the selected fileformats to be displayed in the textbox.........
Using flb As New FolderBrowserDialog
If flb.ShowDialog() = Windows.Forms.DialogResult.OK Then
ListBox1.Items.Clear()
TextBox1.Text = flb.SelectedPath
Dim fileNames As String() = Directory.GetFiles(flb.SelectedPath)
Dim selectedFiles As String() = From fileName In fileNames Where fileName.EndsWith(".rtf") Or fileName.EndsWith(".doc") Select fileName
For Each filename In selectedFiles
ListBox1.Items.Add(filename)
Next
End If
End Using
推荐答案
使用目录的两字符串重载.GetFiles方法: ^ ]
第二个字符串仅允许您检索与选择字符串("* .rtf"或"* .doc")匹配的文件
Use the two-string overload of the directory.GetFiles method: MSDN[^]
The second string allows you to only retrieve the files which match a selection string ("*.rtf" or "*.doc")
这篇关于在下拉菜单中选择.doc或.rtf文件的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文