Hi All,
I have a picturebox on a form containing the photo of a person. As you
advance through the records, the photo updates. Rather than storing the
images in an inefficient blob field in a table, I have the separate images
stored in an image directory with primary key as the filename (3476.jpg). If
the image exists, I display the image. All this works fine.
I have a buttons that allow for the insertion and deletion of photos. The
“add” works fine too. But I am getting errors when I attempt to delete an
image – “file is being used by another process.” The only time the image is
“used” is when I display it on the form. I am assuming the form/picturebox
is locking the image (what else?). I coded the procedure to reset the image
to a default missing image photo. That did not work so I set the picturebox
to nothing first. That did not work either. I also verified the string
being passed to the delete.file method. Here is my code:
Private Sub cmdRemovePhoto_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdRemovePhoto.Click
Dim intReturn As Integer
intReturn = MsgBox("Delete this Photo? This cannot be reversed.",
MsgBoxStyle.YesNo + MsgBoxStyle.Question + MsgBoxStyle.DefaultButton2,
"Warning...")
If intReturn = 6 Then
picPhoto.Image = Nothing
picPhoto.Image = Image.FromFile(pubGlobalSetup &
"\imageFolder\missingphoto.jpg")
Try
File.Delete(pubGlobalSetup & "\imageFolder\" &
LTrim(Str(intContactID)) & ".jpg") ' <--Error Here
cmdRemovePhoto.Enabled = False
Catch ee As Exception
MsgBox(ee.Message)
End Try
End If
End Sub
I would sure appreciate any ideas. This should be easy. I have no clue
what could be locking the file. It has to be the picturebox doesn’t it? But
at the time I am deleting, it has been replaced. I checked the file
attribues at the time I delete and it is set only to "Archive". Someone in
Google had a similar problem and the respondant suggested a file.close
method. There is no such method. There is a fileclose(buffer#) method for
datafiles.
Thanks much!
--
Tom 4 1989
Try loading. Making a in memory copy of the image (drawimage). Dispose
original Image used for load.
Let me know...
-tom
TomA ha scritto:
Hi All,
I have a picturebox on a form containing the photo of a person. As you
advance through the records, the photo updates. Rather than storing the
images in an inefficient blob field in a table, I have the separate images
stored in an image directory with primary key as the filename (3476.jpg). If
the image exists, I display the image. All this works fine.
I have a buttons that allow for the insertion and deletion of photos. The
"add" works fine too. But I am getting errors when I attempt to delete an
image - "file is being used by another process." The only time the image is
"used" is when I display it on the form. I am assuming the form/picturebox
is locking the image (what else?). I coded the procedure to reset the image
to a default missing image photo. That did not work so I set the picturebox
to nothing first. That did not work either. I also verified the string
being passed to the delete.file method. Here is my code:
Private Sub cmdRemovePhoto_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdRemovePhoto.Click
Dim intReturn As Integer
intReturn = MsgBox("Delete this Photo? This cannot be reversed.",
MsgBoxStyle.YesNo + MsgBoxStyle.Question + MsgBoxStyle.DefaultButton2,
"Warning...")
If intReturn = 6 Then
picPhoto.Image = Nothing
picPhoto.Image = Image.FromFile(pubGlobalSetup &
"\imageFolder\missingphoto.jpg")
Try
File.Delete(pubGlobalSetup & "\imageFolder\" &
LTrim(Str(intContactID)) & ".jpg") ' <--Error Here
cmdRemovePhoto.Enabled = False
Catch ee As Exception
MsgBox(ee.Message)
End Try
End If
End Sub
I would sure appreciate any ideas. This should be easy. I have no clue
what could be locking the file. It has to be the picturebox doesn't it? But
at the time I am deleting, it has been replaced. I checked the file
attribues at the time I delete and it is set only to "Archive". Someone in
Google had a similar problem and the respondant suggested a file.close
method. There is no such method. There is a fileclose(buffer#) method for
datafiles.
Thanks much!
--
Tom
"TomA" <To**@discussions.microsoft.comschrieb:
I have a buttons that allow for the insertion and deletion of photos. The
“add” works fine too. But I am getting errors when I attempt to delete an
image – “file is being used by another process.” The only time the image
is
“used” is when I display it on the form. I am assuming the
form/picturebox
is locking the image (what else?).
Check out the snippets in the article below -- they demonstrate ways to load
an image without locking the file:
<URL:http://dotnet.mvps.org/dotnet/code/graphics/#ImageNoLock>
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Thanks Tom (1),
Your suggestion worked. I had to make several changes in the program. In
the event someone else has the same problem and is searching, I loaded the
image clone into the picturebox using the following code:
Private m_Bitmap As Bitmap ' Form level
Dim bm As New Bitmap(ImagefileName)
m_Bitmap = New Bitmap(bm.Width, bm.Height)
Dim gr As Graphics = Graphics.FromImage(m_Bitmap)
gr.DrawImage(bm, 0, 0)
bm.Dispose()
picPhoto.Image = m_Bitmap
The file was no longer locked - the picturebox contained a clone and I
disposed of the original file from memory. I was free to delete the file
without a file locking challenge.
Take care!
Tom (2)
--
Tom
"to**************@uniroma1.it" wrote:
Try loading. Making a in memory copy of the image (drawimage). Dispose
original Image used for load.
Let me know...
-tom
TomA ha scritto:
Hi All,
I have a picturebox on a form containing the photo of a person. As you
advance through the records, the photo updates. Rather than storing the
images in an inefficient blob field in a table, I have the separate images
stored in an image directory with primary key as the filename (3476.jpg). If
the image exists, I display the image. All this works fine.
I have a buttons that allow for the insertion and deletion of photos. The
"add" works fine too. But I am getting errors when I attempt to delete an
image - "file is being used by another process." The only time the image is
"used" is when I display it on the form. I am assuming the form/picturebox
is locking the image (what else?). I coded the procedure to reset the image
to a default missing image photo. That did not work so I set the picturebox
to nothing first. That did not work either. I also verified the string
being passed to the delete.file method. Here is my code:
Private Sub cmdRemovePhoto_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdRemovePhoto.Click
Dim intReturn As Integer
intReturn = MsgBox("Delete this Photo? This cannot be reversed.",
MsgBoxStyle.YesNo + MsgBoxStyle.Question + MsgBoxStyle.DefaultButton2,
"Warning...")
If intReturn = 6 Then
picPhoto.Image = Nothing
picPhoto.Image = Image.FromFile(pubGlobalSetup &
"\imageFolder\missingphoto.jpg")
Try
File.Delete(pubGlobalSetup & "\imageFolder\" &
LTrim(Str(intContactID)) & ".jpg") ' <--Error Here
cmdRemovePhoto.Enabled = False
Catch ee As Exception
MsgBox(ee.Message)
End Try
End If
End Sub
I would sure appreciate any ideas. This should be easy. I have no clue
what could be locking the file. It has to be the picturebox doesn't it? But
at the time I am deleting, it has been replaced. I checked the file
attribues at the time I delete and it is set only to "Archive". Someone in
Google had a similar problem and the respondant suggested a file.close
method. There is no such method. There is a fileclose(buffer#) method for
datafiles.
Thanks much!
--
Tom
It is also nice Herfried's suggestion (the second one) based on
streams.
If you do not need to resize the image, it would be interesting
to measure which one is faster, to use DrawImage or the stream.
I suspect that the second way might be faster.
If you try it out let us know!
-tom (1) :)
TomA ha scritto:
Thanks Tom (1),
Your suggestion worked. I had to make several changes in the program. In
the event someone else has the same problem and is searching, I loaded the
image clone into the picturebox using the following code:
Private m_Bitmap As Bitmap ' Form level
Dim bm As New Bitmap(ImagefileName)
m_Bitmap = New Bitmap(bm.Width, bm.Height)
Dim gr As Graphics = Graphics.FromImage(m_Bitmap)
gr.DrawImage(bm, 0, 0)
bm.Dispose()
picPhoto.Image = m_Bitmap
The file was no longer locked - the picturebox contained a clone and I
disposed of the original file from memory. I was free to delete the file
without a file locking challenge.
Take care!
Tom (2)
--
Tom
"to**************@uniroma1.it" wrote:
Try loading. Making a in memory copy of the image (drawimage). Dispose
original Image used for load.
Let me know...
-tom
TomA ha scritto:
Hi All,
>
I have a picturebox on a form containing the photo of a person. As you
advance through the records, the photo updates. Rather than storing the
images in an inefficient blob field in a table, I have the separate images
stored in an image directory with primary key as the filename (3476.jpg). If
the image exists, I display the image. All this works fine.
>
I have a buttons that allow for the insertion and deletion of photos. The
"add" works fine too. But I am getting errors when I attempt to delete an
image - "file is being used by another process." The only time the image is
"used" is when I display it on the form. I am assuming the form/picturebox
is locking the image (what else?). I coded the procedure to reset the image
to a default missing image photo. That did not work so I set the picturebox
to nothing first. That did not work either. I also verified the string
being passed to the delete.file method. Here is my code:
>
>
Private Sub cmdRemovePhoto_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdRemovePhoto.Click
>
Dim intReturn As Integer
>
intReturn = MsgBox("Delete this Photo? This cannot be reversed.",
MsgBoxStyle.YesNo + MsgBoxStyle.Question + MsgBoxStyle.DefaultButton2,
"Warning...")
>
If intReturn = 6 Then
>
picPhoto.Image = Nothing
>
picPhoto.Image = Image.FromFile(pubGlobalSetup &
"\imageFolder\missingphoto.jpg")
>
Try
>
File.Delete(pubGlobalSetup & "\imageFolder\" &
LTrim(Str(intContactID)) & ".jpg") ' <--Error Here
>
cmdRemovePhoto.Enabled = False
>
Catch ee As Exception
>
MsgBox(ee.Message)
>
End Try
>
End If
>
End Sub
>
>
>
I would sure appreciate any ideas. This should be easy. I have no clue
what could be locking the file. It has to be the picturebox doesn't it? But
at the time I am deleting, it has been replaced. I checked the file
attribues at the time I delete and it is set only to "Archive". Someone in
Google had a similar problem and the respondant suggested a file.close
method. There is no such method. There is a fileclose(buffer#) method for
datafiles.
>
Thanks much!
--
Tom
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Me |
last post by:
Hi Folks,
I'm trying to delete 2 files using fso. The mail file name is stored in an
access db.
using the code below I can delete the main file but not the thumbnail.
The thumbnail has the...
|
by: Tony WONG |
last post by:
i am not sure that this subject can be discussed here.
i have many photos. they are stored according to the name of the EVENT and
YEAR.
i will set up a database (sql or access) to store...
|
by: Ken |
last post by:
I have a database called autographs.mdb that is in the "XYZ" folder in
the "database" folder. I have a form in the database that I want to
display a photo of the celeb on. The photos are in a...
|
by: Frankie |
last post by:
Hello:
I'm coding a website which allows the owner to make add/change/deletes to
his product database, which includes product images stored separately on the
server. I have coded the Delete page...
|
by: Sandeep Singh Sekhon |
last post by:
I am Developing a Web Application with ASP.NET 1.1
I have one project Folder which is virtual directory of IIS.
In this directory, I have one Folder named Photos in which I used to
Store Photos....
|
by: Mike Chen |
last post by:
Dear all,
I made a c# program for my friend's wedding. It slides all photos in
specified folder automatically. To roll the pictures smoothly I firstly scan
and store all pictures in RAM and push...
|
by: FrankB |
last post by:
Hello,
after setting another image to the picture box it is not possible to
delete the last shown file via File.Delete ( sFilename). Path of image
file is correct. Error message box says: file...
|
by: Bart Steur |
last post by:
Hi,
I'm writing an app to maintain products. The products are listed in a
listbox and when I click a product in a listbox some info of that product is
shown including a picture of the product.
...
|
by: krungkrung |
last post by:
hi again to everyone!
I made a simple program(for my VB.Net practice). The program loads an image file to a picturebox upon clicking a button. after loading the image file i have another button to...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |