i can't delete this file, why?

T

Tark Siala

hi

i'm working on VB.NET 203
and i'm working on application that read Metadata from Photo Take it from
Digital Camera.

i'm use this code:

Dim imageX = New Bitmap(PhotoFullFileNameX)
Dim propItems As PropertyItem() = imageX.PropertyItems
....
....
....

it's working good
but after i read information i need delete this file with:

file.Delete(PhotoFullFileNameX)

but i have this error:

An unhandled exception of type 'System.IO.IOException' occurred in
mscorlib.dll
Additional information: The process cannot access the file
"filename.jpg"
because it is being used by another process.

that's mean the file still under open with (bitmap function)
what i must do to close this connection???
--
Best Regards

Tark M. Siala
Development Manager
INTERNATIONAL COMPUTER CENTER (ICC.Networking)
Messenger: (e-mail address removed)
Web Page: http://www.icc-libya.com
======================================
 
A

Armin Zingler

Tark said:
hi

i'm working on VB.NET 203
and i'm working on application that read Metadata from Photo Take it from
Digital Camera.

i'm use this code:

Dim imageX = New Bitmap(PhotoFullFileNameX)
Dim propItems As PropertyItem() = imageX.PropertyItems
....
....
....

it's working good
but after i read information i need delete this file with:

file.Delete(PhotoFullFileNameX)

but i have this error:

An unhandled exception of type 'System.IO.IOException' occurred in
mscorlib.dll
Additional information: The process cannot access the file
"filename.jpg"
because it is being used by another process.

that's mean the file still under open with (bitmap function)
what i must do to close this connection???


Probably you did not dispose imageX before deleting the file. If you want to
delete it and still keep a bitmap in memory, you have to copy imageX to a
new bitmap and dispose imageX before deleting the file.

To copy the bitmap, you can simply write:

dim bmpToKeep as bitmap
bmpToKeep = new bitmap(imageX)



Armin
 
T

Tom John

Dim imageX = New Bitmap(PhotoFullFileNameX)
Dim propItems As PropertyItem() = imageX.PropertyItems
....
....
....

Try opening the image using a stream, which you can close before
deleting:

Dim file As New IO.FileStream("c:\temp\image.gif",
IO.FileMode.Open)
Dim image As Image = image.FromStream(file)
file.Close()
IO.File.Delete("c:\temp\image.gif")

Hope this helps

Tom
 
T

Tark Siala

imageX is Bitmap Object
and when i type imageX.dispose system can't know this method
 
T

Tark Siala

you cant do that
because i use Bitmap Object to get Metadata info
when i use Image Object i can't read Metadata info
 
A

Armin Zingler

Tark said:
imageX is Bitmap Object
and when i type imageX.dispose system can't know this method

I can't reproduce this. Dispose is not an advanced member, so it should be
shown always. Isn't it listed via intellisense or doesn't it compile?


Armin
 
T

Tark Siala

hi
when i did what you tell, i get the Error Message:

A generic error occurred in GDI+

maby image from file stream not support metadata.
 
T

Tark Siala

hi
very thanx about your idea
its working good, first i can't see (Despose) method in imageX
but now it is working

i make small software thats renaming Digital Photo from
Camera to Take Date and Time.
and read original DateTime from JPG files
if you have any good idea please tell me.

from: DSC11234.jpg
to: 20050411 - 223440 (Sony - DSC-41).jpg

and move files to date structure Folders

c:\2005
c:\2005\200504
c:\2005\200504\20050411
===> Photo Files

it's working good now
thanks again
--
Best Regards

Tark M. Siala
Tripoli - Libya
======================================
 
C

Chris Dunaway

Bitmap inherits from Image so you should be able to do what you want.

Dim file As New IO.FileStream("c:\temp\image.gif", IO.FileMode.Open)
Dim b As Bitmap = DirectCast(Image.FromStream(file),Bitmap)
file.Close()
IO.File.Delete("c:\temp\image.gif")
 

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

Top