Open a txt file when a button clicked in VB.NET

69,945

Solution 1

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

Solution 2

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
Share:
69,945
User7291
Author by

User7291

Software Engineer

Updated on July 28, 2020

Comments

  • User7291
    User7291 almost 4 years

    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 OpenFileDialog tool?

    Note that I'm using VB.NET 2010.