purejamie
asked on
system.io.path.GetTempFileName - Can't delete it!
Hello Experts,
Hopefully this one will be an easy one for someone!
I am creating a temp file using 'system.io.path.gettempfil ename' to use within a sub, however, when I try to delete it at the end of the sub it returns the message - "The process can not acces the file <filename I created earlier> because it is being used by another process" . In a nutshell, the code would look like this:
dim strFilename as string = system.io.path.gettempfile name
<Do stuff with the file, in this case using it to generate new transforms for MSI's>
system.io.file.delete(strf ilename)
I have tried using marshal and garbage collection to release the file for deletion with no luck. Any Comcontrol's etc. that could possibly be holding the file open are also closed. Any help would be greatly appreciated.
Cheers,
Jamie.
Hopefully this one will be an easy one for someone!
I am creating a temp file using 'system.io.path.gettempfil
dim strFilename as string = system.io.path.gettempfile
<Do stuff with the file, in this case using it to generate new transforms for MSI's>
system.io.file.delete(strf
I have tried using marshal and garbage collection to release the file for deletion with no luck. Any Comcontrol's etc. that could possibly be holding the file open are also closed. Any help would be greatly appreciated.
Cheers,
Jamie.
Let's start with something simple...
Did you perform a "close" operation on the FileStream/TextWriter/etc that you used to write to the file?
Did you perform a "close" operation on the FileStream/TextWriter/etc that you used to write to the file?
ASKER
Hi there,
The gettempfilename command creates a 0 byte file on the disk and passes back the path as the string. This is then used as a path for some Msi Transform stuff. The file is not created as an object in the traditional sense - therefore, doing a strFileName.close will not work (as it is a string). I'm afriad waiting doesn't make a difference either - any operations are definately complete on the file by this time. I think it is something to do with how the tempfile is created?
Cheers,
Jamie.
The gettempfilename command creates a 0 byte file on the disk and passes back the path as the string. This is then used as a path for some Msi Transform stuff. The file is not created as an object in the traditional sense - therefore, doing a strFileName.close will not work (as it is a string). I'm afriad waiting doesn't make a difference either - any operations are definately complete on the file by this time. I think it is something to do with how the tempfile is created?
Cheers,
Jamie.
ASKER
Hello again,
Thanks again for the replies. I am using the file in the following way - (strTempMsiFilename is the temp file created as above)
Dim objDatabase As Object = objInstaller.opendatabase( strTempMsi FileName, 1)
At the end of the sub I have cleared objDatabase.
Thanks for any help.
Cheers,
Jamie.
Thanks again for the replies. I am using the file in the following way - (strTempMsiFilename is the temp file created as above)
Dim objDatabase As Object = objInstaller.opendatabase(
At the end of the sub I have cleared objDatabase.
Thanks for any help.
Cheers,
Jamie.
ASKER
Sorry, one more thing - DjDez - you can sleep threads using 'system.threading.thread.s leep' if that is any use to you!?
Cheers,
Jamie.
Cheers,
Jamie.
yea, i forgot all about threading!
Cheers
Dez
Cheers
Dez
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi guys,
It is now sorted! I had fully commited the database changes but it got me looking at the comObjects again, I then realised my mistake (hadn't released *all* the comobjects used).. So thanks for getting me to look in the right direction ;) !!!
Cheers,
Jamie.
It is now sorted! I had fully commited the database changes but it got me looking at the comObjects again, I then realised my mistake (hadn't released *all* the comobjects used).. So thanks for getting me to look in the right direction ;) !!!
Cheers,
Jamie.
Dez