A
AussieRules
Hi,
I have a process that writes an image file out to disk.
I reuse the same file name over and over, as there is only every one file
required. THe problem is that when this code executes for the second time,
the file.delete errors with
The process cannot access the file 'file' becuase it is being used by
another process.
Should the close I have at the end of my close, not do this ?
After this code, a picturebox1 is set to point to this filename. On the
closing of that form with the picture box I have a dispose method, which I
figured woulld release the file as well. Seems not, or my dispose technique
is a bit wrong.
any tips on this one
Thanks
If File.Exists(filename) Then
File.Delete(filename)
End If
Dim PictureCol As Integer = 0 ' the column # of the BLOB field
Dim cmd As New SqlCommand("SELECT image FROM tbl_image WHERE image_id =" &
intImageID, SqlConnection)
Try
Dim dr As SqlDataReader = cmd.ExecuteReader()
dr.Read()
Dim b(dr.GetBytes(PictureCol, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
dr.GetBytes(PictureCol, 0, b, 0, b.Length)
dr.Close()
Dim fs As New System.IO.FileStream(filename, IO.FileMode.Create,
IO.FileAccess.Write)
fs.Write(b, 0, b.Length)
fs.Flush()
fs.Close()
Application.DoEvents()
Catch
MsgBox(Err.Description)
End Try
I have a process that writes an image file out to disk.
I reuse the same file name over and over, as there is only every one file
required. THe problem is that when this code executes for the second time,
the file.delete errors with
The process cannot access the file 'file' becuase it is being used by
another process.
Should the close I have at the end of my close, not do this ?
After this code, a picturebox1 is set to point to this filename. On the
closing of that form with the picture box I have a dispose method, which I
figured woulld release the file as well. Seems not, or my dispose technique
is a bit wrong.
any tips on this one
Thanks
If File.Exists(filename) Then
File.Delete(filename)
End If
Dim PictureCol As Integer = 0 ' the column # of the BLOB field
Dim cmd As New SqlCommand("SELECT image FROM tbl_image WHERE image_id =" &
intImageID, SqlConnection)
Try
Dim dr As SqlDataReader = cmd.ExecuteReader()
dr.Read()
Dim b(dr.GetBytes(PictureCol, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
dr.GetBytes(PictureCol, 0, b, 0, b.Length)
dr.Close()
Dim fs As New System.IO.FileStream(filename, IO.FileMode.Create,
IO.FileAccess.Write)
fs.Write(b, 0, b.Length)
fs.Flush()
fs.Close()
Application.DoEvents()
Catch
MsgBox(Err.Description)
End Try