I'm new to .Net (just a couple days) so there might be a better way to
do this.
Question: What does "Empty" mean? Is the file empty if it contains one
space? Is it empty if it doesn't exist?
You can check the length of an existing file to see if it's greater
than zero but, by definition, you can't see what;'s inside of it
without opening it.
==== To check the length of a text file ====
Dim FileSize As Long
Try
FileSize = FileLen("C:\Som eFile.Txt")
Catch exc As FileNotFoundExc eption
FileSize = 0
Finally
Select Case FileSize
Case Is > 0
MsgBox("NON EMPTY: " & FileSize.ToStri ng)
Case Else
MsgBox("EMPTY")
End Select
End Try
==== To read a text file: ====
Dim myStreamReader As StreamReader
myStreamReader = File.OpenText(" C:\SomeFile.Txt ")
Me.txtFileText. Text = myStreamReader. ReadToEnd()
If Not myStreamReader Is Nothing Then
myStreamReader. Close()
End If
On Thu, 18 Sep 2003 11:50:37 -0700, "Sender" <us**@domain.co m> wrote:
I have two questions:
(1) I just want to check whether a .txt file is empty or not (without
opening it). Like I click on a command button then it should give message
EMPTY if is empty and show message "NON EMPTY" if it is not empty.
(2) What are the steps to open a notepad file (C:\XYZ\abc.txt ) in a VB Text
Box.
Thanks