使用vb.net中的浏览按钮打开文件 [英] opening the file using browse button in vb.net

查看:247
本文介绍了使用vb.net中的浏览按钮打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的编码中,我无法查看(.rtf)和(.doc)文件
请通过以下代码为我提供指导


here in the below coding i cant able to view the (.rtf) and (.doc) files
so kindly guide me with below coding


Imports System.IO
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Using fold As New OpenFileDialog
            fold.Filter = "document files (*.doc)|*.doc |richtext format(*.rtf) | *.rtf |All files (*.*)|*.*"
            fold.Title = "Select file"
            If fold.ShowDialog() = Windows.Forms.DialogResult.OK Then
                ' fold.FilterIndex = 2
                fold.RestoreDirectory = True
                MessageBox.Show("You selected " & fold.FileName)
            End If
        End Using
    End Sub
End Class

推荐答案

您需要使用此
删除过滤器中的空格
You need to remove the spaces in your filters use this

fold.Filter = "document files (*.doc)|*.doc|richtext format(*.rtf)|*.rtf|All files (*.*)|*.*"


之间不应有空格文件声明.试试这个

You should not have any spaces between your file declarations. Try this

Using fold As New OpenFileDialog
           fold.Filter = "document files (*.doc)|*.docx|richtextformat files (*.rtf)|*.rtf|All files (*.*)|*.*"
           fold.Title = "Select file"
           If fold.ShowDialog() = Windows.Forms.DialogResult.OK Then
               'fold.FilterIndex = 2
               fold.RestoreDirectory = True
               MessageBox.Show("You selected " & fold.FileName)
           End If
       End Using



希望对您有帮助



Hope this helps


这篇关于使用vb.net中的浏览按钮打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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