473,473 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

to kill a file

I have this problem when I'm trying to delete a temporal file I made, the
problem is I create this file from a Twain source and then make a temp file
to do some editing to it, I assing the mantioned file to a picturebox and
work from there, when the form closes I try to delete the file and I keep on
getting that the file is used by another process and that it can't be
accessed. I tried disposing and setting to nothing the picturebox but it
still wont let me erase the file. Any ideas?
Basically I'm doing this:
picturebox01.Image = Bitmap.FromFile("tmp.jpg") 'In the load event of the
form

and

File.Delete(Application.StartupPath.ToString & "\tmp.jpg") 'in the onclosing
sub

Help will be really apretiated.

Thanks in advanced. BTW all this is in a form thats a child MDI if this
helps at all.

Alvaro
Nov 21 '05 #1
4 1192
Alvaro Lamas wrote:
I have this problem when I'm trying to delete a temporal file I made, the
problem is I create this file from a Twain source and then make a temp file
to do some editing to it, I assing the mantioned file to a picturebox and
work from there, when the form closes I try to delete the file and I keep on
getting that the file is used by another process and that it can't be
accessed. I tried disposing and setting to nothing the picturebox but it
still wont let me erase the file. Any ideas?
Basically I'm doing this:
picturebox01.Image = Bitmap.FromFile("tmp.jpg") 'In the load event of the
form

and

File.Delete(Application.StartupPath.ToString & "\tmp.jpg") 'in the onclosing
sub

Help will be really apretiated.

Thanks in advanced. BTW all this is in a form thats a child MDI if this
helps at all.

Alvaro


Have you also tried to dispose the bitmap object?
If not, try something like this:

Dim temp As System.Drawing.Bitmap
temp = picturebox01.Image
temp.Dispose()
Nov 21 '05 #2
"Alvaro Lamas" <al****@kreasoft.com.mx> schrieb:
I have this problem when I'm trying to delete a temporal file I made, the
problem is I create this file from a Twain source and then make a temp file
to do some editing to it, I assing the mantioned file to a picturebox and
work from there, when the form closes I try to delete the file and I keep
on getting that the file is used by another process and that it can't be
accessed.


\\\
Dim fs As New FileStream("C:\WINDOWS\Angler.bmp", FileMode.Open)
Dim bmp As New Bitmap(fs)
..
..
..
bmp.Dispose()
fs.Close()
///

- or -

\\\
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://classicvb.org/petition/>

Nov 21 '05 #3
Tried that and a couple of variations of the same thing and nothing =(

Thanks for the suggestion, any other ideas?
Alvaro

"Gianluca Di Bucci" <gl*****@hotmail.com> escribió en el mensaje
news:7W**********************@news3.tin.it...
Alvaro Lamas wrote:
I have this problem when I'm trying to delete a temporal file I made, the
problem is I create this file from a Twain source and then make a temp
file to do some editing to it, I assing the mantioned file to a
picturebox and work from there, when the form closes I try to delete the
file and I keep on getting that the file is used by another process and
that it can't be accessed. I tried disposing and setting to nothing the
picturebox but it still wont let me erase the file. Any ideas?
Basically I'm doing this:
picturebox01.Image = Bitmap.FromFile("tmp.jpg") 'In the load event of the
form

and

File.Delete(Application.StartupPath.ToString & "\tmp.jpg") 'in the
onclosing sub

Help will be really apretiated.

Thanks in advanced. BTW all this is in a form thats a child MDI if this
helps at all.

Alvaro


Have you also tried to dispose the bitmap object?
If not, try something like this:

Dim temp As System.Drawing.Bitmap
temp = picturebox01.Image
temp.Dispose()

Nov 21 '05 #4
Thanks! it works perfectly!

Alvaro

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> escribió en el mensaje
news:%2****************@TK2MSFTNGP10.phx.gbl...
"Alvaro Lamas" <al****@kreasoft.com.mx> schrieb:
I have this problem when I'm trying to delete a temporal file I made, the
problem is I create this file from a Twain source and then make a temp
file to do some editing to it, I assing the mantioned file to a picturebox
and work from there, when the form closes I try to delete the file and I
keep on getting that the file is used by another process and that it can't
be accessed.


\\\
Dim fs As New FileStream("C:\WINDOWS\Angler.bmp", FileMode.Open)
Dim bmp As New Bitmap(fs)
.
.
.
bmp.Dispose()
fs.Close()
///

- or -

\\\
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://classicvb.org/petition/>

Nov 21 '05 #5

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

Similar topics

0
by: Markus Poehler | last post by:
Hi my program should run on terminal server. I open Acrobat process and I have to kill them at some points in my application. This fails cause of insufficient rights on terminal server. the...
12
by: Steve | last post by:
AccessXP in Access2000 mode I have the following code outline in a standard module in MyDatabase.mdb --- Use CreateDatabase to create MyOtherDatabase.mdb Use two make table queries to create...
7
by: David Mitchell | last post by:
I use a function to read all of the files from a couple of directories (and subfolders) and update a table(tblfiles) with the fullpath and file name, the filesize and the date the file was created....
7
by: Mal Reeve | last post by:
Hi, I am using the KILL command to either empty a directory, or delete a file. How do I test for the files existence first, since attempting to delete a non-existent file causes an error. I...
0
by: lynn | last post by:
I'm doing a c# asp.net web application. It create a process "A" to excute an .exe file. This exe file is compiled from c++. In this exe file it will create another new process "B" to excute another...
0
by: WATYF | last post by:
This is my problem... I have some code that starts a Process and returns it to a variable... (prcBat) At any time while that process is running... I want to be able to Kill it by pressing a...
3
by: Scott | last post by:
Hello, I am running into a problem with my code and can't seem to figure out the solution. I know it has to do with the pciture box control and unloading the image inthe picture box but I can't...
5
by: Dino Buljubasic | last post by:
My application can allow a user to open a file for viewing by fetching file data from database, creating the file in a temp directory and starting appropriate process (i.e. Adobe or any other...
14
by: Dixie | last post by:
I am trying to write some code that when I exit my application kills all of the text files in a certain folder. It is possible that some of those files are locked because someone else is using...
10
by: I. Myself | last post by:
Suppose we spawn a child process with Popen. I'm thinking of an executable file, like a compiled C program. Suppose it is supposed to run for one minute, but it just keeps going and going. Does...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
1
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...
0
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...
0
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...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.