|
situation:
I'v created a form with loads server usercontrols. In those usercontrols are all images in a certain folder.
Problem:
I want the user to be able to select one and press delete so that the file is deleted from the hard drive.
I know the path from the file (= property in usercontrol) but when I use
system.io.file.delete(path) I get the folowing message:
"The process cannot access the file 'C:\Documents and Settings\Tom\Mijn documenten\Mijn afbeeldingen\Kopie van Winter.jpg' because it is being used by another process."
After some research I found out that when I use picterbox1.image = Drawing.Image.FromFile(path) vb apperently keeps a link to the file and keeps this file locked.
I thought about declaring a new bitmap put the image in that one and use the internal bitmap. this works fine but the problem I have then is that my tif files only display 1 page and since the program is going to be used in an envoriment where the have alot of tif files (or file like it (more than 1 page in the image file)) this is not really an option.
Anyone know how I can onluck the file so that I can delete it?
|
|
|
|
|
Once presumes that once you delete the file from disk, you no longer show it in the user interface. If so, the solution is to remove the image from the user interface first, then delete the file.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton
My website
|
|
|
|
|
I'v done this
I first clear the image out of the picterbox
then I remove the usercontrol
picturbox.image = nothing
flowlayoutpanel.controls.remove(usercontrol)
file.delete(path)
this is my complete code for the delete button
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
If MessageBox.Show("Bent u zeker dat u deze file DEFINITIEF wilt verwijderen?", "Bevestiging", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.OK Then
For Each c As Control In flp.Controls
If c.GetType.Equals(GetType(Preview)) Then
Dim pr As Preview = c
If pr.checked Then
pr.Image = Nothing
flp.Controls.Remove(c)
File.Delete(pr.Path)
End If
End If
Next
End If
End Sub
strangly enough I can remove the usercontrol while looping in de controls (thought that wasn't possible since I'v had a simular problem with remove a while back)
but when vb tries to delete the file I get the error
|
|
|
|
|
You haven't disposed of the image just set its reference to Nothing. That means it will be upto the garbage collector when it will actually release the file handle.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton
My website
|
|
|
|
|
I do this immidiatly after loading the image into the picturebox:
Dim im As Image = Drawing.Image.FromFile(path)
pic.Image = im
im = Nothing
is this what you mean by disposing the image?
|
|
|
|
|
TDDragon wrote: Dim im As Image = Drawing.Image.FromFile(path)
pic.Image = im
im = Nothing
All this does is set the reference that im holds to nothing. The object still exists because you passed the reference to it to pic.Image.
Remember, most (the vast majority) of object types are reference types. Setting a variable to nothing just means the variable's reference is set to nothing. It does not mean the object ceased to exist. If something else is using the actual object then it will continue to exist.
TDDragon wrote: is this what you mean by disposing the image?
No. Look for the Dispose() method.
Do NOT Dispose an object that is in use. Only Dispose of an object when it is no longer needed.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton
My website
|
|
|
|
|
I got it working with the dispose method
thank you very much
|
|
|
|
|
The real solution is to not use FromFile in the first place. See this[^] for the way around this little limitation.
|
|
|
|
|
I've tried the workaround but this doesn't work for me.
The images to be displayed are mostly TIF files (more than 1 page in 1 image) and with the workaround there is only 1 page (the first one) that the stream contains
|
|
|
|
|
Works fine for me.
GDI+ support for TIF files is a bit lacking. JPEG compressed TIFs are not supported by GDI, along with a few other things that I can't remember off the top of my head.
|
|
|
|
|
Is there a way to force the garbage collector to run ?
|
|
|
|
|
TDDragon wrote: Is there a way to force the garbage collector to run ?
Yes. But that is unadvisable. The garbage collector is tuned to keep your application running as smoothly as possible. Forcing it to collect may harm the performance of your application. Also, there is no guarantee that it will collect the objects that you want it to collect. It decides what is in the best interests of your application with respect to the current environment.
If objects contain unmanaged resources, such as Image s, the there will be a Dispose method. (Or Close on stream like objects).
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
* Reading: Developer Day 5
Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton
My website
|
|
|
|
|
Hello,
I am working on a windows application .net 2.0.
I would like to be able to write my own patch application myself that would update small changes in my main application that has been installed on the customer's computer.
I would like for them just to install a small patch, rather than build a setup program.
Can anyone point me in the right direction for creating a patch application for a windows application.
Thanks very much in advance,
Steve
|
|
|
|
|
Why reinvent the wheel that's but invented a dozen times already? How much work are you going to put into this, at such and such $ an hour versus using something off the shelf to do the same thing? How is your version going to be better than the ones you get off the shelf?
Just a thought...
Basically, you'd doing a byte-for-byte compare of the two versions of the files. You create a database of all the changes to have to make, byte-for-byte, to a certain version of a file, then your patch app has to identify the version of the file thats already installed, read the patch database to see if that version of the file is patchable, make a backup copy of the to-be-patched file, then go through and write each byte-change the database specifies.
You'll have to create a database for EACH VERSION of EACH FILE you want to change. So, if you have to files in your application that need changes, but there are 2 versions of your appout there, say v1.0 and v1.5, that need to be upgraded to a third version, say v2.0, you have to create 4 tables worth of changes.
Those table will be built by comparing both files in v1.0 to v2.0 to generate the changes for both files, AND another set comparing the v1.5 files to v2.0.
|
|
|
|
|
Clocking features are provided for through the integrated use of magnetic card reader/hand held bar code scanner. once the employee scan the card the system should save the time. is there any coding to do this..
pls help
|
|
|
|
|
Barcode readers and magnetic strip readers put keystrokes into the keyboard buffer, so there for you need to put a textbox control onto your form to capture the barcode into.
On the textbox leave event, get the current system time and write it to your database with the Employee Id
Steve Jowett
-------------------------
Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
|
|
|
|
|
can you give me a sample coding..
thanks
|
|
|
|
|
Hi,
I am looping through the controls of the web page, and checking for checkboxes only. Then to be able to check if a checkbox is checked, I need to do a cast of the control to a checkbox. Please see how I did it (the name of the function where this code is in is called CreateSelectiveSQLStatement:
For Each child As Control In c.Controls
Me.CreateSelectiveSQLStatement(child)
If TypeOf child Is CheckBox Then
'Response.Write(child.ID & "<br />")
Dim chk As CheckBox = CType(child, CheckBox)
' Check if checkbox is checked
If chk.Checked Then
strFields = strFields & child.ID & ", "
Response.Write(chk.ID & "<br />")
End If
End If
Next
It doesn't display anything on the web page. Where is my error? I think it might be at:
Dim chk As CheckBox = CType(child, CheckBox)
Please can someone help me? I am using VB.NET 1.1.
Regards
ma se
|
|
|
|
|
I seem to have found my problem, I used DirectCast instead of CType, not sure why it doesn't work with CType? Maybe someone can help explain?
|
|
|
|
|
Hi
does anyone know how to get the arrow keys to respond to a flash game in a webbrowser control?
thanks
Kevin
|
|
|
|
|
Not a VB question, is it?
Steve Jowett
-------------------------
Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
|
|
|
|
|
Hi Steve,
this relates to the VB.NET web browser control.
|
|
|
|
|
Is the Web Browser control not a part of Internet Explorer?
Are you trying to get vb app to responed to your keypresses or your Flash app?
Steve Jowett
-------------------------
Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'
|
|
|
|
|
You'll have to explain what your doing more than this. Key's don't respond to anything, other than someone pressing them. What are you doing with the Flash game?
|
|
|
|
|
Hi Dave
I have written a small VB.NET app which includes a webbrowser control. It works fine but when playing flash games from websites I cannot get the arrow keys to respond. The flash game uses the arrow keys for playing a game. The arrow keys work fine in Internet Explorer. Any ideas?
thanks
|
|
|
|