PC Review


Reply
Thread Tools Rate Thread

Can't move tif file after reading it to picturebox

 
 
yoav
Guest
Posts: n/a
 
      10th Apr 2006
Hi Folks,

The following code crashes on the last statement with a "The process
cannot access the file because it is being used by another process"
exception (fiFax is a FileInfo object):

Dim picbox As New PictureBox
picbox.Image = Drawing.Image.FromFile(fiFax.FullName)
picbox.Dispose()
fiFax.MoveTo(fiFax.Directory.FullName & "\Old\" &
fiFax.Name) ' Exception!!!

If I put the "fiFax.MoveTo" statement before the "FromFile" it works.
Why does the picturebox keeps the file locked even after it is
disposed? How can I release it?

TIA

 
Reply With Quote
 
 
 
 
Michael D. Ober
Guest
Posts: n/a
 
      10th Apr 2006

This appears to be a bug in the Windows API itself. The workaround is to
create a dummy tif image and load it into the picbox before attempting to
move the original image. I have the same problem in one of my older
programs that uses the Kodak Image OCX drivers.

Mike Ober

"yoav" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Folks,
>
> The following code crashes on the last statement with a "The process
> cannot access the file because it is being used by another process"
> exception (fiFax is a FileInfo object):
>
> Dim picbox As New PictureBox
> picbox.Image = Drawing.Image.FromFile(fiFax.FullName)
> picbox.Dispose()


picbox.Image = new Drawing.Image

or

picbox.Image = Drawing.Image.FromFile("dummy.tif")

> fiFax.MoveTo(fiFax.Directory.FullName & "\Old\" &
> fiFax.Name) ' Exception!!!
>
> If I put the "fiFax.MoveTo" statement before the "FromFile" it works.
> Why does the picturebox keeps the file locked even after it is
> disposed? How can I release it?
>
> TIA
>
>




 
Reply With Quote
 
yoav
Guest
Posts: n/a
 
      11th Apr 2006
Hi Mike,

I tried your suggestion but the file was still locked. However, I
solved it using:

picbox.Image.Dispose()

before attempting to move the file.

Thanks


Michael D. Ober wrote:
> This appears to be a bug in the Windows API itself. The workaround is to
> create a dummy tif image and load it into the picbox before attempting to
> move the original image. I have the same problem in one of my older
> programs that uses the Kodak Image OCX drivers.
>
> Mike Ober
>
> "yoav" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi Folks,
> >
> > The following code crashes on the last statement with a "The process
> > cannot access the file because it is being used by another process"
> > exception (fiFax is a FileInfo object):
> >
> > Dim picbox As New PictureBox
> > picbox.Image = Drawing.Image.FromFile(fiFax.FullName)
> > picbox.Dispose()

>
> picbox.Image = new Drawing.Image
>
> or
>
> picbox.Image = Drawing.Image.FromFile("dummy.tif")
>
> > fiFax.MoveTo(fiFax.Directory.FullName & "\Old\" &
> > fiFax.Name) ' Exception!!!
> >
> > If I put the "fiFax.MoveTo" statement before the "FromFile" it works.
> > Why does the picturebox keeps the file locked even after it is
> > disposed? How can I release it?
> >
> > TIA
> >
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PictureBox "locks" file, cannot move/delete gerardianlewis@yahoo.com Microsoft VB .NET 5 2nd Dec 2008 10:46 AM
Move Picturebox within its parent sam Microsoft Dot NET Framework Forms 1 31st Oct 2005 08:12 AM
URI Formats are not supported when PictureBox.Image Loads, How to load http images to picturebox in windows application thedebugger Microsoft C# .NET 2 19th Oct 2004 09:21 AM
how to move previous recond in reading txt file Louis Microsoft Access Form Coding 2 5th Mar 2004 06:53 PM
Reading metafile or gif from clipboard to picturebox B. Cline Microsoft VB .NET 2 29th Dec 2003 06:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:02 AM.