By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,417 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,417 IT Pros & Developers. It's quick & easy.

Temp Files

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

Nov 16 '05 #2

P: n/a

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
On Fri, 4 Mar 2005 00:00:47 +0530, "Harsh Vardhan Singh"
<ha*******************@yahoo.com> wrote:
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.
Nov 16 '05 #3

P: n/a
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

"Harsh Vardhan Singh" <ha*******************@yahoo.com> wrote in message
news:O6*************@TK2MSFTNGP15.phx.gbl...
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

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.