Temp Files

  • Thread starter Thread starter Harsh Vardhan Singh
  • Start date Start date
H

Harsh Vardhan Singh

hi,

i am trying to create a temporary file associated with a particular process.
For instance, i have a windows application which will create a temp file as
soon as it this program is executed. Now i want this temp file to be
destroyed if this application is closed / crashes. Is this possible?

Please help.
Thanks in advance,
Harsh
 
Did you try deleting the temp file in the Dispose and finalizer
methods? You can have a class representing the temp file. The Dispose
method would delete the file and you'd call this method in normal
situations. For abnormal situations, the finalizer would get called by
the CLR and would delete the file.

Regards
Senthil
 
I don't think it's possible with pure .NET code but is possible with a
p/invoke call to CreateFile with FILE_ATTRIBUTE_TEMPORARY and
FILE_FLAG_DELETE_ON_CLOSE flags. You can then create a FileStream
from the result with the IntPtr constructor and use the like you would
a natively created .NET FileStream.

HTH,

Sam


hi,

i am trying to create a temporary file associated with a particular process.
For instance, i have a windows application which will create a temp file as
soon as it this program is executed. Now i want this temp file to be
destroyed if this application is closed / crashes. Is this possible?

Please help.
Thanks in advance,
Harsh

B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
 
thanx for the suggestions but i still hvnt been able to solve the problem
:( ... i think it wud help if i explain what i am trying to do... basically
i hv to prevent a file from being accessed by two users (on different pcs)
simultaneously.. so i want to create a temp file as soon as one user
accesses that file.. now when someone else tries to open it, i first check
if the temp file is present or not...if it is, then i dont allow the other
user to access the file... this part is fine... but the problem is removing
the temp file in case the program crashes... coz if the file is not removed
then no user will be able to access it again unless the temp file is
manually deleted....
i tried creating a class which represents this file and tried to delete the
temp file in the dispose function.. but the file wasnt deleted in case of
program crashing...

this is why i wanted to know if there can be temp files created and
destroyed along with a particular process...

thanx again for the help
harsh
 
Back
Top