473,396 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Temporary file Management

Hi,

I have a few questions about best practices when it comes to the management
of temporary files. Any thoughts anyone can give would be much appreciated.

Basically, I'm writing a document storage app - a Windows service acts as
the file sotrage server and remote windows forms clients send files to the
server to be stored. The temporary files become involved when a client
wishes to view a file that is stored on the server (the server sends a byte
array containing the file's data, the client writes this to a temporary
location and then executes the viewing application to view the temporary
file).

My queries are:

1) Who should be responsible for deleting the temporary file?
2) If my client is responsible for deleting the file, how do I know if the
user has closed the viewer application?
3) What is the best way to detect changes to the file if the user edits the
document in the viewer application?

My own thoughts so far are:

1) My client app is responsible for deleting the file (wishful thinking that
it isn't ;)

2) When I launch the process to view the file, I keep track of it and delete
the temp file when the process exits. The problem with this is what do I do
if the user exits my application before they exit the viewer application?
Also, what happens if they keep the viewer open, but opens another file
unrelated to my application?

3) Use FileSystemWatcher to watch the file for changes. Again, what happens
if the user exits my application before exiting the viewer?

Any thoughts would be appreciated,

Best Regards,

Trev.
Jul 21 '05 #1
6 1815
Hello Trev,

Thanks for your post. I reviewed your description carefully, and now I'd
like to share the following information with you:
1) Who should be responsible for deleting the temporary file?
2) If my client is responsible for deleting the file, how do I know if the user has closed the viewer application? 3) What is the best way to detect changes to the file if the user edits

the document in the viewer application?

I believe the best method to work around this problem is to delete the
temporary file in the viewer application. The viewer application need to
delete a temporary file under the following situations:
1. When it will be closes.
2. When a user want to open another file, it needs to detele the previous
one.

Hope this helps. I look forward to your feedback.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #2
Hi,

Thanks for your help on this, but I have a few extra thoughts:
The viewer application need to
delete a temporary file under
the following situations:
1. When it will be closes.
What happens if my client viewer application is closed before the user had
finished viewing the file (e.g. with Microsoft Word or notepad etc.?) Is
there any way of reliably detecting if the document has been closed and is
safe to delete?
2. When a user want to open
another file, it needs to detele
the previous one.


Again, how can I reliably detect if the user has closed the first file?

Thanks again for your help,

Trev.
Jul 21 '05 #3
Thanks for the help. When I get around to implementing it, I'll post the
final algorithm here in case anybody else is interested.

Best Regards,

Trev.

"Tian Min Huang" <ti******@online.microsoft.com> wrote in message
news:3N**************@cpmsftngxa07.phx.gbl...
Hello Trev,

Thanks for your reply.
What happens if my client viewer application is closed before the user
had finished viewing the file (e.g. with Microsoft Word or notepad etc.?)
Is there any way of reliably detecting if the document has been closed and
is safe to delete?

According to my understanding, when the client viewer application is

close, the temp file will at least be closed. I am afraid that we are not able to
know whether a user had finished viewing the file or not when the file is
closed. If you are mentioning the situation when the viewer application is
closed unexpectablly say, power failure, etc. I suggest that you can use
the algorithmn in viewer app below:

1. Viewer app starts.
2. Read the registry for any remaining file information, clear the registry and delete the files.
3. Log the file information to registry, and then open the file.
4. When the app will be closed nomally, remove the file information from
registry.

Note: You can also log the file manipulation in viewer app to other
persistent storage say, file, instead of the registry.

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #4
Hello Trev,

Thanks for your reply.
What happens if my client viewer application is closed before the user

had finished viewing the file (e.g. with Microsoft Word or notepad etc.?)
Is there any way of reliably detecting if the document has been closed and
is safe to delete?

According to my understanding, when the client viewer application is close,
the temp file will at least be closed. I am afraid that we are not able to
know whether a user had finished viewing the file or not when the file is
closed. If you are mentioning the situation when the viewer application is
closed unexpectablly say, power failure, etc. I suggest that you can use
the algorithmn in viewer app below:

1. Viewer app starts.
2. Read the registry for any remaining file information, clear the registry
and delete the files.
3. Log the file information to registry, and then open the file.
4. When the app will be closed nomally, remove the file information from
registry.

Note: You can also log the file manipulation in viewer app to other
persistent storage say, file, instead of the registry.

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #5
Cor
Hi Codemonkey,

A thoughts of your question that you can use I think.
There is already a thread so I do not repeat, however I did not see this in
it.

There is on every window computer a temp directory (a pity not enumerated by
the special folder).

I think that is the place for your temp files.

A user has tools to delete that or does that by hand.

My 2 eurocents.

Cor
Jul 21 '05 #6
Cheers Cor.

Finding the Temp folder is easy enough. Try "System.IO.Path.GetTempPath" or
"System.IO.Path.GetTempFileName" if you want a unique file name.
A user has tools to delete that or does that by hand.
Lol. Yeah. I would have thought by now there would have been a better, more
robust method of managing temproary files built into windows by now. I vote
for a non-persistable virtual RAM disk that can act as a normal folder that
gets cleared on system startup.

Cheers,

Trev.
"Cor" <no*@non.com> wrote in message
news:Oh**************@TK2MSFTNGP12.phx.gbl... Hi Codemonkey,

A thoughts of your question that you can use I think.
There is already a thread so I do not repeat, however I did not see this in it.

There is on every window computer a temp directory (a pity not enumerated by the special folder).

I think that is the place for your temp files.

A user has tools to delete that or does that by hand.

My 2 eurocents.

Cor



Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jason Charalambides | last post by:
I set a program to automatically load values from a temporary file. However, there is a chance that the specific temporary file "C:\Temp\TU.tmp" may not exist at all. In that case I want that...
4
by: Frank Millman | last post by:
Hi all I need to generate potentially large reports from a database, and I want to offer the option of print preview before actually printing (using wxPython). I figure that the best way to...
2
by: Oswaldo Castro | last post by:
Hi All I found some files in mysql directory with names like #sql-358_2698.MYD. Is this a temporary file created by an alter table statement? May I delete it since all my tables are ok? ...
6
by: Codemonkey | last post by:
Hi, I have a few questions about best practices when it comes to the management of temporary files. Any thoughts anyone can give would be much appreciated. Basically, I'm writing a document...
2
by: Lyners | last post by:
I am creating a temporary file using GetTempFileName to populate it with Excel information. Everything is working correctly except the temporary file name extension is .tmp. How can I change it to...
4
by: lwoods | last post by:
I need to create a temporary file on a server. How do I do it? I tried using IO.Path but it created a local file; i.e., file://C:...... TIA, lwoods
2
by: Brad Pears | last post by:
I have a bytearray variable and want to create a temporary file on my hard disk from this bytearray so I can print this data. How do I do this?? Thanks, Brad
3
crystal2005
by: crystal2005 | last post by:
Hi all, Basically, i'm trying to create temporary file using TemporaryFile() module. TemporaryFile( ]]]]) It's done perfectly to create an intended file. But, i encountered a problem to...
1
by: rparimi | last post by:
Hello pythoners, When I create temporary file using the tempfile module, and forkI) later on in my program, I always see errors when the program exits. Is this because the child process deletes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.