title: The process cannot access the file because it is being used by another process.-error while writing to a file in vb.net
body: <p>in my vb.net code im using streamwriter to write to a file that has been given as input to the form.</p>
  
  <pre><code> Dim strContents As String
          Dim objReader As StreamReader
          Try
  
              objReader = New StreamReader("C:\test.txt")
              strContents = objReader.ReadToEnd()
              objReader.Close()
  
          Catch Ex As Exception
  
          End Try
          Dim Contents As String
          Dim bAns As Boolean = False
          Dim objWriter As StreamWriter
          Dim FileStream As System.IO.FileStream
          Try
  
              FileStream = New FileStream("C:\test.txt", FileMode.Open, FileAccess.ReadWrite)
  
              objWriter = New StreamWriter("C:\test.txt")
              objWriter.Write("fdgdfgdjkljljklg")
              objWriter.Close()
              bAns = True
          Catch Ex As Exception
  
  
          End Try
  </code></pre>
  
  <p>in some of the systems its working fine but in some other workstations its showing error that mentioned in the subject.</p>
  
  <p>What restricts the access to the file here?
  can anyone help me on this?</p>