|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
knowing when file has been totally transferredlet'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? 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] Show quoteHide quote "chad" <c***@discussions.microsoft.com> schreef in bericht news:E09788E6-8E4F-4C3B-BA31-5FB1608859C5@microsoft.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? > > > uhm..... what method do you use when you wanna find out if we get exclusive
access to the file? Show quoteHide quote "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" <c***@discussions.microsoft.com> schreef in bericht > news:E09788E6-8E4F-4C3B-BA31-5FB1608859C5@microsoft.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? > > > > > > > > > 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] Show quoteHide quote "chad" <c***@discussions.microsoft.com> schreef in bericht news:577F14C8-A022-45D1-BCF8-409FA09D8D85@microsoft.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" <c***@discussions.microsoft.com> schreef in bericht >> news:E09788E6-8E4F-4C3B-BA31-5FB1608859C5@microsoft.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? >> > >> > >> > >> >> >> 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. 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 Show quoteHide quote "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. > > 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 Show quoteHide quote "dan m" <dan m@discussions.microsoft.com> wrote in message news:B5052B87-BD67-43FF-91EC-FB181E293F39@microsoft.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. >> >> 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 Show quoteHide quote "dan m" <dan m@discussions.microsoft.com> wrote in message news:B5052B87-BD67-43FF-91EC-FB181E293F39@microsoft.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. >> >>
Is there a Filename.IsValid function anywhere?
radio button user settings Confused Using VB in VS2003 urgent: formatting XL cells Reusing VB.NET Form dialogs in VC apps Populating a combobox from dataset Starter Kit Problem Using new control that inherits from Form Working with data adapter/binding source at runtime Combobox, Count Entries |
|||||||||||||||||||||||