|
-
Apr 1st, 2009, 10:21 AM
#1
Thread Starter
Fanatic Member
[Resolved]Files modified by VB are in a locked state
I have some code that does a Find & Replace in some text files, and closes the file when complete. However, when I try to use the Kill command in VB to cleanup these files (they are temporary files) when the program is closed, I get errors that the file is in use by another app or process. Is there a way I can force these files to close first? This also happens when I scan a document using the EZTWAIN.dll Scan to native function. Everything goes fine, but if I try to scan again to overwrite the file, the file is in use. This is happening on Windows Vista SP1. Maybe I am missing an important step somewhere, but I don't understand why my app isn't releasing the files. Thanks for any help on this issue.
-jeremy
Last edited by hipopony66; Apr 8th, 2009 at 02:01 PM.
Reason: Resolved
-
Apr 1st, 2009, 10:30 AM
#2
Re: Files modified by VB are in a locked state
Could you show us the code you're using to open, edit, and close the files?
-
Apr 1st, 2009, 01:51 PM
#3
Lively Member
Re: Files modified by VB are in a locked state
are you working with these files as fileinfo objects? or are you opening a filestream and writing to a file?
I've run into tons of issues with fileinfo and IO locking. On a polling/ftp application I did a while back i found out that releasing references to a fileinfo object doesn't signal for the locks to release too. In my experiences I had to do a Using Filestream / End Using and then attempt to kill the file.
-
Apr 8th, 2009, 11:45 AM
#4
Thread Starter
Fanatic Member
Re: Files modified by VB are in a locked state
The issue appears to be with an image I am loading into a Picturebox control with and OpenFileDialog control. It appears the handle to the file is remaining open after image has been loading into the picture box. Any idea how to make VB close the file handle? My code to load the image to the picturebox with a command button is below:
Code:
Dim OpenPic As New OpenFileDialog
Dim strClientPicPath As String
With OpenPic
.CheckFileExists = True
.ShowReadOnly = False
.Filter = "JPEG (*.jpg) |*.jpg"
.FilterIndex = 2
If .ShowDialog = DialogResult.OK Then
' Load the specified file into a PictureBox control.
strClientPicPath = OpenPic.FileName
frmCropImage.pbImageCrop.Image = Image.FromFile(.FileName)
End If
End With
Me.Enabled = False
frmCropImage.Show()
Thanks for any suggestions.
-Jeremy
-
Apr 8th, 2009, 11:50 AM
#5
Re: Files modified by VB are in a locked state
Image.FromFile does not close the filestream created when opening the image. Use the PictureBox' Load method instead.
-
Apr 8th, 2009, 11:52 AM
#6
Re: Files modified by VB are in a locked state
-
Apr 8th, 2009, 01:17 PM
#7
Thread Starter
Fanatic Member
Re: Files modified by VB are in a locked state
Which method will allow me to modify the least amount of my existing code? I need to use the OpenFileDialog control for the user to browse to the image, but I need to load it into the picturebox without it remaining locked. All examples I found using the Picturebox.load method referred to loading a URL image.
Also, I can't simply use:
Code:
frmCropImage.pbImageCrop.Image = Image.FromStream(.FileName)
because the (.Filename) is a string, not system.io.
Thanks for suggestions.
-Jeremy
-
Apr 8th, 2009, 01:19 PM
#8
Re: Files modified by VB are in a locked state
Have you tried the Load method?
-
Apr 8th, 2009, 01:32 PM
#9
Thread Starter
Fanatic Member
Re: Files modified by VB are in a locked state
So I need to store the path of the openfiledialog selected file as a bitmap and then paint the bitmap into the picturebox? Is that the easiest method?
thanks
-
Apr 8th, 2009, 01:37 PM
#10
Re: Files modified by VB are in a locked state
No, just use the Load method:
Code:
frmCropImage.pbImageCrop.Load(.FileName)
-
Apr 8th, 2009, 02:00 PM
#11
Thread Starter
Fanatic Member
Re: Files modified by VB are in a locked state
Oh, Ok. That is MUCH easier. Thanks for the help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|