Reputation:
I have the following code:
If line = Nothing Then
MsgBox("Login failed.")
Using sw As New StreamWriter(File.Open(Index.strLogPath, FileMode.OpenOrCreate)) ' open or create a new file at our path
sw.BaseStream.Seek(0, SeekOrigin.End) ' append new users to the end
sw.AutoFlush = True
sw.WriteLine("line is nothing")
sw.Flush()
sw.Close()
End Using
End If
My line = nothing condition is met, the msgbox pops up letting me know, but the file is not created. If the file is there, nothing is added to it.
I have checked the path validity, and ensured that applications have permission there, everything I can think of isn't working, and to make it more frustrating there are no errors! Any help would be greatly appreciated.
Upvotes: 0
Views: 144
Reputation: 14088
Did you know that the File
class already has a utility method to do exactly that?
File.AppendAllText(Index.strLogPath, "line is nothing")
Should be as simple as that. :)
EDIT
If you insist on managing the file stream yourself, try this:
Using sw As New StreamWriter(File.Open(Index.strLogPath, FileMode.Append)) ' open or create a new file at our path
sw.WriteLine("line is nothing")
End Using
Points of interest:
FileMode.Append
instead of OpenOrCreate
Upvotes: 1