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

knowing when file has been totally transferred

P: n/a
let's say I'm transferring a large file like 100MB over to a folder.

The program detects when the file arrives. However, I can't
figure out how to know when the file is totally transferred over.

One unsuccessful method is to...

dim fi as new fileinfo(newfile)

fi.length returns the supposed size of the file. But it correctly
reports the final size of the file the moment transferring
starts. So that's no help at all.

I want to know what the file is totally transferred to the folder
so I can then begin to work on it. Any ideas?

Apr 17 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Well i would do the following

i would use a filesystem watcher to detect the arrival of the file (
Created event ) this event will fire as soon as the transfer starts
however it will also provide us the location and name of the file so we can
wait in a loop untill we can get exclusive access to the file
when this is possible we know that the file is completely transfered

regards

Michel Posseth [MCP]

"chad" <ch**@discussions.microsoft.com> schreef in bericht
news:E0**********************************@microsof t.com...
let's say I'm transferring a large file like 100MB over to a folder.

The program detects when the file arrives. However, I can't
figure out how to know when the file is totally transferred over.

One unsuccessful method is to...

dim fi as new fileinfo(newfile)

fi.length returns the supposed size of the file. But it correctly
reports the final size of the file the moment transferring
starts. So that's no help at all.

I want to know what the file is totally transferred to the folder
so I can then begin to work on it. Any ideas?

Apr 17 '06 #2

P: n/a
uhm..... what method do you use when you wanna find out if we get exclusive
access to the file?

"Michel Posseth [MCP]" wrote:
Well i would do the following

i would use a filesystem watcher to detect the arrival of the file (
Created event ) this event will fire as soon as the transfer starts
however it will also provide us the location and name of the file so we can
wait in a loop untill we can get exclusive access to the file
when this is possible we know that the file is completely transfered

regards

Michel Posseth [MCP]

"chad" <ch**@discussions.microsoft.com> schreef in bericht
news:E0**********************************@microsof t.com...
let's say I'm transferring a large file like 100MB over to a folder.

The program detects when the file arrives. However, I can't
figure out how to know when the file is totally transferred over.

One unsuccessful method is to...

dim fi as new fileinfo(newfile)

fi.length returns the supposed size of the file. But it correctly
reports the final size of the file the moment transferring
starts. So that's no help at all.

I want to know what the file is totally transferred to the folder
so I can then begin to work on it. Any ideas?


Apr 17 '06 #3

P: n/a

open the file in a try catch block and use
FileShare.None as the share parameter to a FileStream object

you might wrap this in a nice function

regards

Michel Posseth [MCP]
"chad" <ch**@discussions.microsoft.com> schreef in bericht
news:57**********************************@microsof t.com...
uhm..... what method do you use when you wanna find out if we get
exclusive
access to the file?

"Michel Posseth [MCP]" wrote:
Well i would do the following

i would use a filesystem watcher to detect the arrival of the file (
Created event ) this event will fire as soon as the transfer starts
however it will also provide us the location and name of the file so we
can
wait in a loop untill we can get exclusive access to the file
when this is possible we know that the file is completely transfered

regards

Michel Posseth [MCP]

"chad" <ch**@discussions.microsoft.com> schreef in bericht
news:E0**********************************@microsof t.com...
> let's say I'm transferring a large file like 100MB over to a folder.
>
> The program detects when the file arrives. However, I can't
> figure out how to know when the file is totally transferred over.
>
> One unsuccessful method is to...
>
> dim fi as new fileinfo(newfile)
>
> fi.length returns the supposed size of the file. But it correctly
> reports the final size of the file the moment transferring
> starts. So that's no help at all.
>
> I want to know what the file is totally transferred to the folder
> so I can then begin to work on it. Any ideas?
>
>
>


Apr 17 '06 #4

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

Apr 18 '06 #5

P: n/a
thanks guys. that helped a lot :-)
Apr 19 '06 #6

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


Jan 15 '07 #7

P: n/a
I have used the code below to determine when a file upload is finished
before making a thumbnail of the file. It has always worked for me. It
appears that the file.exists does not equal to true until the file has been
totally uploaded.
Dim fi As New System.IO.FileInfo(Server.MapPath(".") & "\Photos\" &
FileUpload1.FileName)
Do While fi.Exists = False
'do nothing
Loop
"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.


Jan 15 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.