Hi all:
I am trying to generate a file.
I have a sub called generateHeaders(). That is responsible for generating header info for the file.
I am supposed to then write other info to that file. This is done in the sub generateInsertFile(). In that sub, I open a streamwriter to that same file in the generateHeader() sub, and append the neccessary info after the header.
Thing is I get this very annoying IOEXception :'The process cannot access the File 'insert_item.qli' because its in use by another process'.
I tried closing the streamwriter after using it, but it didn't work.
Any ideas for solving this? Its quite an annoying exception
.
Heres my code (VB.net 2008 express)
I am trying to generate a file.
I have a sub called generateHeaders(). That is responsible for generating header info for the file.
I am supposed to then write other info to that file. This is done in the sub generateInsertFile(). In that sub, I open a streamwriter to that same file in the generateHeader() sub, and append the neccessary info after the header.
Thing is I get this very annoying IOEXception :'The process cannot access the File 'insert_item.qli' because its in use by another process'.
I tried closing the streamwriter after using it, but it didn't work.
Any ideas for solving this? Its quite an annoying exception
Heres my code (VB.net 2008 express)
VB.NET:
Sub generateHeaders()
'generate header for insert_item.qli
'this is the file which gives the exception, but its not thrown here
Dim Iwriter As New StreamWriter(configFileDir & "\insert_item.qli")
Iwriter.WriteLine("@fields")
Iwriter.WriteLine("@ITEM_DF")
Iwriter.Close()
End Sub
VB.NET:
Sub generateInsertFile(ByVal tname2 As String, ByVal line2 As String())
Try
'At this point, that annoying exception is thrown
Dim insertwriter As New StreamWriter(configFileDir & "\insert_item.qli")
insertwriter.WriteLine(tname2)
Dim i As Integer
For i = 3 To line2.Length - 2
insertwriter.Write("\" & line2(i) & "\" & ",")
Next
'write the last line
insertwriter.Write("\" & line2(line2.Length - 1) & "\")
insertwriter.WriteLine()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub