473,386 Members | 2,129 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,386 software developers and data experts.

Deleting a file

Hello All,

I have a picturebox on a VB.NET form. I use an OpenfileDialog to select an
image for the picturebox (pb.image=image.fromfile(Openfiledialog.fileame)).
Once the image is loaded, I want to delete the file using
file.delete(OpenfileDialog.filename). however, this is throwing an exception
saying that the file is in use by another application.

After I load the image, what do I have to do to release the file so I can
delete it?

Regards,
Lee
Nov 21 '05 #1
4 1186
Hi,

If you dont load an image from a filestream it locks the image.

Dim img As Image

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

img = Image.FromStream(fs)

PictureBox1.Image = img

fs.Close()

Ken

-------------------
"lgbjr" <lg***@online.nospam> wrote in message
news:Om**************@TK2MSFTNGP12.phx.gbl...
Hello All,

I have a picturebox on a VB.NET form. I use an OpenfileDialog to select an
image for the picturebox (pb.image=image.fromfile(Openfiledialog.fileame)).
Once the image is loaded, I want to delete the file using
file.delete(OpenfileDialog.filename). however, this is throwing an exception
saying that the file is in use by another application.

After I load the image, what do I have to do to release the file so I can
delete it?

Regards,
Lee

Nov 21 '05 #2
Thanks Ken! That works!

Thanks

Lee

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi,

If you dont load an image from a filestream it locks the image.

Dim img As Image

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

img = Image.FromStream(fs)

PictureBox1.Image = img

fs.Close()

Ken

-------------------
"lgbjr" <lg***@online.nospam> wrote in message
news:Om**************@TK2MSFTNGP12.phx.gbl...
Hello All,

I have a picturebox on a VB.NET form. I use an OpenfileDialog to select an
image for the picturebox
(pb.image=image.fromfile(Openfiledialog.fileame)).
Once the image is loaded, I want to delete the file using
file.delete(OpenfileDialog.filename). however, this is throwing an
exception
saying that the file is in use by another application.

After I load the image, what do I have to do to release the file so I can
delete it?

Regards,
Lee

Nov 21 '05 #3
"Ken Tucker [MVP]" <vb***@bellsouth.net> schrieb:
If you dont load an image from a filestream it locks the image.

Dim img As Image

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

img = Image.FromStream(fs)

PictureBox1.Image = img

fs.Close()


Documentation on 'Image.FromStream':

---
*Remarks*

You must keep the stream open for the lifetime of the 'Image' object.
---

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4
"lgbjr" <lg***@online.nospam> schrieb:
After I load the image, what do I have to do to release the file so I can
delete it?


For example:

\\\
Dim b1 As New Bitmap("C:\WINDOWS\Angler.bmp")
Dim b2 As New Bitmap(b1.Width, b1.Height, ...)
Dim g As Graphics = Graphics.FromImage(b2)
g.DrawImageUnscaled(b1, ...)
g.Dispose()
b1.Dispose()
Me.PictureBox1.Image = b2
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

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

Similar topics

13
by: Bob Darlington | last post by:
I have a repair and backup database routine which runs when a user closes down my application. It works fine in my development machine, but breaks on a client's at the following line: If...
4
by: al havrilla | last post by:
hi all what does the phrase: "scalar deleting destructor" mean? i'm getting this in a debug error message using c++ 7.1 thanks Al
2
by: GMK | last post by:
Dear all in my asp.net application i have a text file that is installed with my application on the server. this text file is filled with data through a web interface in my application. i need to...
5
by: George | last post by:
VB.net 2003 standard, XP windows home edition. Installed first application OK today. When I removed the application via Control Panel, there were no problems and the app folders were deleted. ...
8
by: shandra | last post by:
I have a file I need to delete or truncate. I tried using the KILL command in VB6. I tried using the file.delete command in VB.net. I tried manually deleting, renaming, and copying over the...
2
by: SiouxieQ | last post by:
Hi there, I'm using the code below to try to delete a name from a list of names in a file. Unfortunately it doesn't quite do what I want it to. Instead of looking for the name in the...
5
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....
3
by: Kimera.Kimera | last post by:
I'm trying to write a program in VB.net 2003 that basically deletes all files, folders, sub-folders and sub-sub folders (etc). The program is simply for deleting the Windows/Temp folder contents,...
13
by: programming | last post by:
how do i delete from a text file 1 of the following lines: jon|scott adam|smith <--delete paul|clark say i would like to delete the middle line of this txt, in member.txt what php code or...
1
by: diyasher | last post by:
hello my code is in c#. i am using fileSystemWatcher class to watch event when file is deleted. event is fire when file is deleted, i want to stop deleting file, means when user want to delete...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
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...

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.