Help - Search - Members - Calendar
Full Version: Deleting a file in VB.Net
BleepingComputer.com > Software > Programming
   
aommaster
Hi guys!

I have a program that reads a chm file through this function:
CODE
System.Windows.Forms.Help.ShowHelp(Me, tempfolder & "/Help.chm", HelpNavigator.AssociateIndex)


Now, I would like to delete it when the program closes.

So far I have this:
CODE
If System.IO.File.Exists(tempfolder & "/preview.html") Then
    SetAttr(tempfolder & "/preview.html", FileAttribute.Normal)
    Kill(tempfolder & "/preview.html")
End If

However, the above fails, because apparently, the Help.ShowHelp class uses a read/write attribute (I cannot have a read only for some reason. If I do, the help window does not open).

Is there any way of deleting this file ones the program terminates?

Thanks guys!
Billy O'Neal
Hello smile.gif

It's probably failing because the program's still open.

Kill(tempfolder & "/preview.html") <-- the HTML file is not what's running -- whatever displays the file is what's running. You'd have to enumerate the program that was actually used to open it from the HKEY_CLASSES_ROOT registry key and kill that process.

Billy3
aommaster
Hi Billy!

Thanks for your reply. Yes, that was a typo on my part because there are two files that need to be deleted (preview.html being one of them). How would the process go if I'd like to delete the help.chm file?
aommaster
Hi Billy!

Perhaps you could also provide me with a more efficient way of doing this. The reason I wanted to delete the file is that the chm file is created in a temporary directory and then opened. However, once the program is closed, I'd like the chm file to be deleted. I could just leave the file there, but I like to clean up after myself.

Would there be a way of perhaps embedding the chm file into the program? However, I can't see how to call the chm file from the my.resources once it has been embedded.

Edit: Solved my problem! smile.gif I used a function instead of a sub and manually allocated a process using the system.diagnostics.process.

Thanks Billy!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.