to kill a file

  • Thread starter Thread starter Alvaro Lamas
  • Start date Start date
A

Alvaro Lamas

I have this problem when I'm trying to delete a temporal file I made, the
problem is I create this file from a Twain source and then make a temp file
to do some editing to it, I assing the mantioned file to a picturebox and
work from there, when the form closes I try to delete the file and I keep on
getting that the file is used by another process and that it can't be
accessed. I tried disposing and setting to nothing the picturebox but it
still wont let me erase the file. Any ideas?
Basically I'm doing this:
picturebox01.Image = Bitmap.FromFile("tmp.jpg") 'In the load event of the
form

and

File.Delete(Application.StartupPath.ToString & "\tmp.jpg") 'in the onclosing
sub

Help will be really apretiated.

Thanks in advanced. BTW all this is in a form thats a child MDI if this
helps at all.

Alvaro
 
Alvaro said:
I have this problem when I'm trying to delete a temporal file I made, the
problem is I create this file from a Twain source and then make a temp file
to do some editing to it, I assing the mantioned file to a picturebox and
work from there, when the form closes I try to delete the file and I keep on
getting that the file is used by another process and that it can't be
accessed. I tried disposing and setting to nothing the picturebox but it
still wont let me erase the file. Any ideas?
Basically I'm doing this:
picturebox01.Image = Bitmap.FromFile("tmp.jpg") 'In the load event of the
form

and

File.Delete(Application.StartupPath.ToString & "\tmp.jpg") 'in the onclosing
sub

Help will be really apretiated.

Thanks in advanced. BTW all this is in a form thats a child MDI if this
helps at all.

Alvaro

Have you also tried to dispose the bitmap object?
If not, try something like this:

Dim temp As System.Drawing.Bitmap
temp = picturebox01.Image
temp.Dispose()
 
Alvaro Lamas said:
I have this problem when I'm trying to delete a temporal file I made, the
problem is I create this file from a Twain source and then make a temp file
to do some editing to it, I assing the mantioned file to a picturebox and
work from there, when the form closes I try to delete the file and I keep
on getting that the file is used by another process and that it can't be
accessed.

\\\
Dim fs As New FileStream("C:\WINDOWS\Angler.bmp", FileMode.Open)
Dim bmp As New Bitmap(fs)
..
..
..
bmp.Dispose()
fs.Close()
///

- or -

\\\
Dim b1 As New Bitmap("C:\WINDOWS\Angler.bmp")
Dim b2 As New Bitmap(b1.Width, b1.Height, ...)
Dim g As Graphics = Graphics.FromImage(b2)
g.DrawImageUnscaled(b1, ...)
g.Dispose()
b1.Dispose()
Me.PictureBox1.Image = b2
///
 
Tried that and a couple of variations of the same thing and nothing =(

Thanks for the suggestion, any other ideas?
Alvaro
 
Thanks! it works perfectly!

Alvaro

Herfried K. Wagner said:
\\\
Dim fs As New FileStream("C:\WINDOWS\Angler.bmp", FileMode.Open)
Dim bmp As New Bitmap(fs)
.
.
.
bmp.Dispose()
fs.Close()
///

- or -

\\\
Dim b1 As New Bitmap("C:\WINDOWS\Angler.bmp")
Dim b2 As New Bitmap(b1.Width, b1.Height, ...)
Dim g As Graphics = Graphics.FromImage(b2)
g.DrawImageUnscaled(b1, ...)
g.Dispose()
b1.Dispose()
Me.PictureBox1.Image = b2
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top