By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,289 Members | 3,049 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,289 IT Pros & Developers. It's quick & easy.

i can't delete this file, why?

P: n/a
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: ta*******@hotmail.com
Web Page: http://www.icc-libya.com
======================================
Nov 21 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Tark Siala schrieb:
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
Nov 21 '05 #2

P: n/a
thx
but how i can dispose imageX ?

--
======================================
"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Tark Siala schrieb:
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

Nov 21 '05 #3

P: n/a
On Thu, 14 Jul 2005 14:47:07 +0200, "Tark Siala"
<ta*******@icc-libya.com> wrote:
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
Nov 21 '05 #4

P: n/a
Tark Siala schrieb:
thx
but how i can dispose imageX ?


imageX.Dispose
Armin
Nov 21 '05 #5

P: n/a
imageX is Bitmap Object
and when i type imageX.dispose system can't know this method
"Armin Zingler" <az*******@freenet.de> wrote in message
news:eC**************@TK2MSFTNGP10.phx.gbl...
Tark Siala schrieb:
thx
but how i can dispose imageX ?


imageX.Dispose
Armin

Nov 21 '05 #6

P: n/a
you cant do that
because i use Bitmap Object to get Metadata info
when i use Image Object i can't read Metadata info

--
Best Regards

Tark M. Siala
======================================
"Tom John" <forums[at]redfrog[dot]com> wrote in message
news:hs********************************@4ax.com...
On Thu, 14 Jul 2005 14:47:07 +0200, "Tark Siala"
<ta*******@icc-libya.com> wrote:
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

Nov 21 '05 #7

P: n/a
Tark Siala schrieb:
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
Nov 21 '05 #8

P: n/a
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")

Nov 21 '05 #9

P: n/a
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.
--
Best Regards
======================================
"Tom John" <forums[at]redfrog[dot]com> wrote in message
news:hs********************************@4ax.com...
On Thu, 14 Jul 2005 14:47:07 +0200, "Tark Siala"
<ta*******@icc-libya.com> wrote:
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

Nov 21 '05 #10

P: n/a
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
======================================
"Armin Zingler" <az*******@freenet.de> wrote in message
news:ee*************@tk2msftngp13.phx.gbl...
Tark Siala schrieb:
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

Nov 21 '05 #11

P: n/a
Please note that the method FromStream locks the file until the object is
disposed.
You could look at the documentation of the method at
http://msdn.microsoft.com/library/de...filetopic1.asp

--
Regards
Mohamed El Ashmawy
MEA Developer Support Center
ITWorx on behalf of Microsoft EMEA GTSC
"Tark Siala" <ta*******@icc-libya.com> wrote in message
news:ef*************@tk2msftngp13.phx.gbl...
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.
--
Best Regards
======================================
"Tom John" <forums[at]redfrog[dot]com> wrote in message
news:hs********************************@4ax.com...
On Thu, 14 Jul 2005 14:47:07 +0200, "Tark Siala"
<ta*******@icc-libya.com> wrote:
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


Nov 21 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.