Error: being used by another process
I can write this file but i get and error file being used by another process. Can't seem to figure out what I have left open
Thanks
Code:
Sub WriteData()
'On Error GoTo ErrHandler
Dim str As New IO.FileStream(CBProgramPath & "\Setup.ini", IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.ReadWrite)
Using writer As StreamWriter = New StreamWriter(str)
writer.WriteLine(txtCompany.Text)
writer.WriteLine(txtContact.Text)
writer.WriteLine(txtAddress.Text)
writer.WriteLine(txtCity.Text)
writer.WriteLine(txtState.Text)
writer.WriteLine(txtZipCode.Text)
writer.WriteLine(txtPhone.Text)
writer.WriteLine(txtFax.Text)
writer.WriteLine(txtEMail.Text)
writer.Close()
str.Close()
End Using
Exit Sub
'ErrHandler:
'MsgBox("Error Writing Setup File")
End Sub
Sub LoadData()
Try
' Create an instance of StreamReader to read from a file.
Dim sr As StreamReader = New StreamReader(CBProgramPath & "\Setup.ini")
Dim line(11) As String
Dim X As Integer
' Read and display the lines from the file until the end
' of the file is reached.
X = 1
Do
line(X) = sr.ReadLine()
'Console.WriteLine(line)
X = X + 1
'Transfer Data
txtCompany.Text = line(1)
txtContact.Text = line(2)
txtAddress.Text = line(3)
txtCity.Text = line(4)
txtState.Text = line(5)
txtZipCode.Text = line(6)
txtPhone.Text = line(7)
txtFax.Text = line(8)
txtEMail.Text = line(9)
Loop Until line Is Nothing
sr.Close()
sr.Dispose()
sr = Nothing
Catch E As Exception
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
Console.WriteLine(E.Message)
End Try
End Sub
Re: Error: being used by another process
You sure your not using it somewhere else, or maybe a previous exception still has it open?
Re: Error: being used by another process
I am only using StreamWriter/Reader one place, That is in the code I posted. I really have no idea anymore where is wrong Am I not closing soomething?