Writing to text file with StreamWriter. File used by another process

83 Views Asked by At

The answer to this is probably really simple and basic, however im having trouble when writing to a file as I am greeted with this error message.

"IO Exception was unhandled."

"The process cannot access the file 'C:\Users\Steven\Documents\Visual Studio 2010\Projects\SmithsSocialCare\Login Information.txt' because it is being used by another process."

This is the code in question.

Dim FileW As System.IO.StreamWriter
Dim Username As String
Dim Password As String
FileW = My.Computer.FileSystem.OpenTextFileWriter("C:\Users\Steven\Documents\Visual Studio 2010\Projects\SmithsSocialCare\Login Information.txt", True)
If TxtPass.Text = TxtPass2.Text Then
        Username = TxtUser.Text
        Password = TxtPass.Text
        FileW.WriteLine(Username & " " & Password)
        FileW.Close()
End If

Cheers in advance, Steven.

0

There are 0 best solutions below