10

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
User7291
  • 1,095
  • 3
  • 29
  • 71

2 Answers2

28
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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
VB.NET LEARNER
  • 711
  • 5
  • 11
5

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
VB.NET LEARNER
  • 711
  • 5
  • 11
Mousa Alfhaily
  • 1,260
  • 3
  • 20
  • 38