473,326 Members | 2,048 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,326 software developers and data experts.

knowing when file has been totally transferred

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
7 2015
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
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

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
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
thanks guys. that helped a lot :-)
Apr 19 '06 #6
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Marcus | last post by:
Hi all, Quick question... I have a class that is over 1200 lines of code and 50 KB in size. This file does not display any html, it is just included and after I call all the necessary...
2
by: Jason | last post by:
Hi folks. I'm running into a problem figuring out how to proceed with the following. I have files being transferred from several machines through a separate sftp (SSH) connection to a server. I...
8
by: IGC | last post by:
I have a requirement to record in a database when a file is finished downloading to the end-user. Currently when a user clicks a download icon for a file it directs to an ASP page that records the...
9
by: Ian Richardson | last post by:
If I follow the steps on http://www.dhtmlcentral.com/tutorials/tutorials.asp?id=11 to add .js files to a document on demand, let's say by <body onload="blah();">, how can I reliably tell that it...
5
by: JS | last post by:
I have v8.1 fix 5 installed on windows 2k. I compiled a stored procedure in development environment, then used the get routine command to generate the file. I transferred the file to second test...
3
by: Shmulik | last post by:
I have an application written in C# that creates a queue of items to process, connects via a TCP connection to a server on a Unix box, and then passes data files to the Unix box for processing...
30
by: Franck PEREZ | last post by:
Hello, I'm developing a small XML marshaller and I'm facing an annoying issue. Here's some sample code: ########### My test application ############ class Foo(object): #The class I'd like to...
6
by: Jatin | last post by:
Hey Guys I have a web application that allows users to download files. But the files are not hosted on the webserver. The files are stored on external servers and are referenced by a URL/URI....
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.