在 VB.NET 中单击按钮时打开 txt 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18825370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 17:09:21 来源:igfitidea点击:
Open a txt file when a button clicked in VB.NET
提问by User7291
I have a log file in my project. This file is a text file (.txt). Is there a way to open this file when a button clicked without using the OpenFileDialogtool?
我的项目中有一个日志文件。此文件是一个文本文件 (.txt)。有没有办法在不使用OpenFileDialog工具的情况下单击按钮时打开此文件?
Note that I'm using VB.NET 2010.
请注意,我使用的是 VB.NET 2010。
回答by VB.NET LEARNER
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
回答by Mousa Alfhaily
Here is a simple example:
这是一个简单的例子:
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