473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

File handle

I add some JPG files to a imagelist control and bind the imagelist to a
listview control.
This will list out all JPG files in the listview control.
Then I add a "Delete" button for deleting the JPG files.
In the click event of the "Delete" button, I remove the selecteditem from
the listview control and also the physical file.
I'm not able to delete the physical JPG file because an exception is thrown
and said that my program is still using the JPG file.
How to release the JPG file handle after accessing it using "image.fromfile"
?
Thanks.
Nov 21 '05 #1
2 1545
Hi,

Open the image with image.fromstream instead. Image.fromfile locks
the file on the computer.

Dim fs As New System.IO.FileStream("C:\camera.bmp", IO.FileMode.Open)

Dim img As Image = Image.FromStream(fs)

fs.Close()

PictureBox1.Image = img

Ken

------------------------------
"Stanley" <se****@email.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I add some JPG files to a imagelist control and bind the imagelist to a
listview control.
This will list out all JPG files in the listview control.
Then I add a "Delete" button for deleting the JPG files.
In the click event of the "Delete" button, I remove the selecteditem from
the listview control and also the physical file.
I'm not able to delete the physical JPG file because an exception is thrown
and said that my program is still using the JPG file.
How to release the JPG file handle after accessing it using "image.fromfile"
?
Thanks.

Nov 21 '05 #2
Thank you very much.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:ey**************@TK2MSFTNGP09.phx.gbl...
Hi,

Open the image with image.fromstream instead. Image.fromfile locks the file on the computer.

Dim fs As New System.IO.FileStream("C:\camera.bmp", IO.FileMode.Open)

Dim img As Image = Image.FromStream(fs)

fs.Close()

PictureBox1.Image = img

Ken

------------------------------
"Stanley" <se****@email.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I add some JPG files to a imagelist control and bind the imagelist to a
listview control.
This will list out all JPG files in the listview control.
Then I add a "Delete" button for deleting the JPG files.
In the click event of the "Delete" button, I remove the selecteditem from
the listview control and also the physical file.
I'm not able to delete the physical JPG file because an exception is thrown and said that my program is still using the JPG file.
How to release the JPG file handle after accessing it using "image.fromfile" ?
Thanks.

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Kim Jensen | last post by:
I'd like to make a directory listing where instead of the entire filename I need it to show the filename minus the extention and get the value of charname= in the file itself. I've been told...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
5
by: matt dittman | last post by:
I have created a windows service that reads emails from a drop directory and moves them to the appropriate mail folder every 15 seconds. I can move, rename and delete the files as needed, up...
1
by: bissatch | last post by:
Hi, I am currently working on a content management system where a user can fill in a form (title, keywords, link text etc. - all the initial attibutes), which when submitted, will go onto create...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
2
by: Shailesh Gajare | last post by:
Hi All, I have creating an ASP.Net application with two web servers. I am uploading a file which is being uploaded on one of the server, I want to copy the uploaded file on the other server at the...
1
by: Daniel | last post by:
does the windows file handle change? are file handles unique to the whole operating system or just the current directoy? if a file is opened then closed then opened again, does the file handle...
3
by: nicolasg | last post by:
Hi, I'm trying to open a file (any file) in binary mode and save it inside a new text file. After that I want to read the source from the text file and save it back to the disk with its...
3
by: Yang | last post by:
Hi, I'm experiencing a problem when trying to close the file descriptor for a socket, creating another socket, and then closing the file descriptor for that second socket. I can't tell if my issue...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.