Can't write to file

M

Microsoft

I am trying to use the streamwriter to write to a text file

I declare the streamwriter publically at the beginning

im filename As String

Dim Drive As String

Dim oFile As System.IO.File

Dim ofile2 As System.IO.File

Dim nopatch As System.IO.StreamWriter

Dim error1 As System.IO.StreamWriter

Dim testfile As System.IO.StreamWriter

Dim dir As String





After a button click I try to write some data ased on conditions. The files
appear but they are empty. I check the values of the variables and they all
of text associated



'create the initial output files and directories

dir = TextBox3.Text & "\"

Directory.CreateDirectory(dir)

nopatch = oFile.CreateText(dir & "nopatch.txt")

error1 = ofile2.CreateText(dir & "error.txt")

testfile = oFile.CreateText("C:\output\test.txt")

testfile.WriteLine("test")



Actual Write process



Catch ex As Exception

exout = ex.ToString

errorout = computer & "," & servername & "," & exout

error1.WriteLine(errorout)

testfile.WriteLine("test")

testfile.WriteLine(errorout)

End Try
 
M

Microsoft

No error messages, but I figured out that it doesn't write to the file until
I close it. So I am using the append method followed by a close.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top