我的项目中有一个日志文件。该文件是文本文件(.txt)。有没有办法在没有使用OpenFileDialog工具的情况下点击按钮时打开此文件?
请注意,我正在使用VB.NET 2010。
答案 0 :(得分:21)
Dim FILE_NAME As String = "C:\FileName.txt"
If System.IO.File.Exists(FILE_NAME) = True Then
Process.Start(FILE_NAME)
Else
MsgBox("File Does Not Exist")
End If
答案 1 :(得分:5)
这是一个简单的例子:
Public Class OpenTextFile
Private Sub OpenTextFile_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub OpenBUT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenBUT.Click
'OpenBUT_Click the text file
Process.Start("C:\File Name.txt")
End Sub
End Class
答案 2 :(得分:0)
尝试一下
Dim file as string = "whatever file you want"
If System.IO.File.Exists(file) = True Then
Process.Start(file)
Else
MsgBox("File Does Not Exist!!", MsgBoxStyle.Critical)
End If