简体   繁体   English

在 VB.NET 中单击按钮时打开 txt 文件

[英]Open a txt file when a button clicked in VB.NET

I have a log file in my project.我的项目中有一个日志文件。 This file is a text file (.txt).此文件是一个文本文件 (.txt)。 Is there a way to open this file when a button clicked without using the OpenFileDialog tool?有没有办法在不使用OpenFileDialog工具的情况下单击按钮时打开此文件?

Note that I'm using VB.NET 2010.请注意,我使用的是 VB.NET 2010。

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

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

I have a log file in my project.我的项目中有一个日志文件。 This file is a text file (.txt).该文件是文本文件(.txt)。 Is there a way to open this file when a button clicked without using the OpenFileDialog tool?当不使用OpenFileDialog工具单击按钮时,是否可以打开此文件?

Note that I'm using VB.NET 2010.请注意,我正在使用VB.NET 2010。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM