There may be others but one sure-fire way to determine if a file is
available for use is to attempt to open it for exclusive access.
If the attempt fails then it is NOT available.
If the attempt succeeds then it IS available.
The sort of logic you need to do this is (pseudo-code):
Catch the 'Create' event from FileSystemWatcher
While True
Try
Attempt to open the file for exclusive use
....
If the logic gets to here then it succeeded so do whatever you want to
do with the file
....
Exit While
Catch ex As Exception
Check the exception
If it is not the exception that tells us that the file is not
available then deal with it
....
Exit While
End If
If the logic gets to here then the file is not available so allow the
loop to continue
End Try
End While
"dan m" <dan
m@discussions.microsoft.comwrote in message
news:B5**********************************@microsof t.com...
>I am little confused on when and how to rename the originial file and still
get the entire download file. I have filesystemwatcher running on my
server.
If I fire the create event of the watcher don't i still have only a
partial
downloaded file? Does the rename event only fire when the file is
completely
downloaded?
Thanks for any help.
Dan
"Chris Dunaway" wrote:
>Another option is to save the file using a temporary name and then
rename it to the final destination name. That way the
FileSystemWatcher would key on the rename event and you would catch the
file after it was completely transferred.