473,782 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Openf iledialog.filea me)).
Once the image is loaded, I want to delete the file using
file.delete(Ope nfileDialog.fil ename). 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 1208
Hi,

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

Dim img As Image

Dim fs As New System.IO.FileS tream("C:\camer a.bmp", IO.FileMode.Ope n)

img = Image.FromStrea m(fs)

PictureBox1.Ima ge = img

fs.Close()

Ken

-------------------
"lgbjr" <lg***@online.n ospam> wrote in message
news:Om******** ******@TK2MSFTN GP12.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(Openf iledialog.filea me)).
Once the image is loaded, I want to delete the file using
file.delete(Ope nfileDialog.fil ename). 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***@bellsout h.net> wrote in message
news:%2******** *******@TK2MSFT NGP15.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.FileS tream("C:\camer a.bmp", IO.FileMode.Ope n)

img = Image.FromStrea m(fs)

PictureBox1.Ima ge = img

fs.Close()

Ken

-------------------
"lgbjr" <lg***@online.n ospam> wrote in message
news:Om******** ******@TK2MSFTN GP12.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(Openf iledialog.filea me)).
Once the image is loaded, I want to delete the file using
file.delete(Ope nfileDialog.fil ename). 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***@bellsout h.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.FileS tream("C:\camer a.bmp", IO.FileMode.Ope n)

img = Image.FromStrea m(fs)

PictureBox1.Ima ge = img

fs.Close()


Documentation on 'Image.FromStre am':

---
*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.n ospam> 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:\WIND OWS\Angler.bmp" )
Dim b2 As New Bitmap(b1.Width , b1.Height, ...)
Dim g As Graphics = Graphics.FromIm age(b2)
g.DrawImageUnsc aled(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
9538
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 Dir(strLDB) <> "" Then Kill (strLDB) where strLDB is the path to the ldb file. The client advises that the ldb doesn't lurk after the program closes. Any ideas?
4
14030
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
1549
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 know how could i update this text file programatically and using a web interface. what i need is not to over write the content of the text file but to delete it's content and then write a new content. id there any way to do this?
5
2692
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. But when I installed the app from a CD-ROM (Release folder is in D:), when I remove the app in Control Panel these problems occur: Control Panel does not delete the application folders. When I try to delete them I get message "Cannot delete file:...
8
14030
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 file... but nothing works. I keep getting the error: Cannot delete access_log: it is being used by another person or program. I tried shutting down services, I tried killing processes using the task manager, I tried rebooting, and still, I get...
2
1714
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 textbox and deleting that it is just deleting the first line of data in the file.
5
2114
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. On my Web Page, I have a button named delete which I used to delete photo in the folder. But when I click the button and apply the logic to delete the file, it raises an Exception that the access to the file is denied. I am using following code to...
3
2927
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, removing all the files/folders inside it. The problem i am having is that i can only delete files in the Windows/Temp folder, and i can't delete folders if they contain files, i know that you can't do this.
13
2465
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 logic would help me accomplish this?
1
2424
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 file, file cannot be deleted. how to stop deleting file bye
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10311
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6733
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2874
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.