S
Saga
Hi all! Using VB 2008.
I need to write to a text file. Create and write if it does not exist
or append if it does. I have this code:
If System.IO.File.Exists("G:\work\temp\TestTxtFiles\Box\testfile.txt")
Then
'Open file for append.
Using oFile As System.IO.StreamWriter =
System.IO.File.AppendText("G:\work\temp\TestTxtFiles\Box\testfile.txt")
oFile.WriteLine("Test file line 4")
oFile.WriteLine("Test file line 5")
oFile.WriteLine("Test file line 6")
oFile.Close()
End Using
Else
'Create a test text file.
Using oFile As System.IO.StreamWriter =
System.IO.File.CreateText("G:\work\temp\TestTxtFiles\Box\testfile.txt")
oFile.WriteLine("Table CODES")
oFile.WriteLine("Test file line 1")
oFile.WriteLine("Test file line 2")
oFile.WriteLine("Test file line 3")
oFile.Close()
End Using
End If
It works. My question is whether this is the best way to do this or if there
is
a more optimized method. Thanks! Saga
I need to write to a text file. Create and write if it does not exist
or append if it does. I have this code:
If System.IO.File.Exists("G:\work\temp\TestTxtFiles\Box\testfile.txt")
Then
'Open file for append.
Using oFile As System.IO.StreamWriter =
System.IO.File.AppendText("G:\work\temp\TestTxtFiles\Box\testfile.txt")
oFile.WriteLine("Test file line 4")
oFile.WriteLine("Test file line 5")
oFile.WriteLine("Test file line 6")
oFile.Close()
End Using
Else
'Create a test text file.
Using oFile As System.IO.StreamWriter =
System.IO.File.CreateText("G:\work\temp\TestTxtFiles\Box\testfile.txt")
oFile.WriteLine("Table CODES")
oFile.WriteLine("Test file line 1")
oFile.WriteLine("Test file line 2")
oFile.WriteLine("Test file line 3")
oFile.Close()
End Using
End If
It works. My question is whether this is the best way to do this or if there
is
a more optimized method. Thanks! Saga