title: Creating and appending text to txt file in VB.NET
body: <p>Using VB.NET, I am trying to create a text file if it doesn't exist or append text to it if exists.</p>
  
  <p>For some reason, though it is creating the text file I am getting an error saying <em>process cannot access file</em>.</p>
  
  <p>And when I run the program it is writing text, but how can I make it write on a new line?</p>
  
  <pre><code>Dim strFile As String = "C:\ErrorLog_" &amp; DateTime.Today.ToString("dd-MMM-yyyy") &amp; ".txt"
  
  Dim sw As StreamWriter
  Dim fs As FileStream = Nothing
  
  If (Not File.Exists(strFile)) Then
      Try
          fs = File.Create(strFile)
          sw = File.AppendText(strFile)
          sw.WriteLine("Start Error Log for today")
  
      Catch ex As Exception
          MsgBox("Error Creating Log File")
      End Try
  Else
      sw = File.AppendText(strFile)
      sw.WriteLine("Error Message in  Occured at-- " &amp; DateTime.Now)
  
      sw.Close()
  End If
  </code></pre>