File.CopyTo throws Operation Successful error
Hi all,
I'm currently developing an application that transfers a file from a local machine to a remote server via UNC using the System.IO.File.CopyTo command.
What seems to be happening is that with larger files (test file is 80+ megs) the command throws an error during transfer with the message
"The operation completed successfully" and is coming from mscorlib
StackTrace = " at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite)
at System.IO.FileInfo.CopyTo(String destFileName, Boolean overwrite)
at Syst...When using smaller files 1meg - 2megs it works a treat.
Any ideas, thoughts, help is, as always, greatly appreciated.
Cheers
Cam
Answers
Right so my testing goes on and apparently, which i didnt' notice before but under the properties window of the file i was trying to copy/move (right clicked on the file from windows explorer) it said something like the file has been received from a remote computer and the security is blocked.
After selecting the unblock command it now transfers fine.
Can anyone shed any light on this blocking/unblocking feature cause it's news to me.
Cheers
Cam
I feel like I'm talking to myself here
but as I've run into this problem a couple of times I've unearthed some more information that will hopefully help someone else out and not have to suffer through this!Windows XP SP2 and Windows 2003 (and I imagine above) have introduced a new file mechanism called ZoneIdentifiers - which I can only assume (due to lack of documentation) is another shot fired by Microsoft in the battle against viruses/worms etc. that seems to block files that have originated from a remote location from being copied without express constent from the user.
The problem as I see it though is that the ZoneIdentifiers are buggy, to say the least, and files that we've created and copied around our local machines have been block by the OS. Some that have been passed around the domain have been blocked as well (blocking these files down are debatable to say the least).
So for those of you encountering the above problem where a FileCopy (via .NET) is not transferring the file and are getting the message "The operation completely successfully" have a look to see if the source file has been blocked. If so unblock them and try again.
If, in code, you need to unblock them please refer to http://www.jameskovacs.com/blog/PermaLink.aspx?guid=6985963b-3d85-41ae-bca8-5f9efe2a79c7 for a utility (including .NET source code) to remove the ZIs.
Hope this helps someone, somewhere :)
Cheers
Cam Church
All Replies
Sorry one other thing - I'm running this on v2 of the NET framework.
Cheers
Cam
Hey,
Try to wrap your code to copy a file in a try/catch block. From what it looks like, the exception being thrown is type IOException. I'd read about how to use this method and what type of exceptions are generated here.
Hey draykula
Thanks for getting back to me. I do indeed have my code wrapped in a try catch block which is catching an IOException error.
The problem though, is that the error message is "The operation has completed successfully" - when in fact the file has not been copied.
--------------- Code ----------------------
.....
file As New FileInfo(LocalPath) Dim ret As Boolean If RemoteFile = "" Then RemotePath = RemotePath & file.Name If MoveFile ThenDim
file.MoveTo(RemotePath)
Elsefile = file.CopyTo(RemotePath)
End Ifthen further on I catch the IO exception from thrown by the CopyTo method
ioEx As IOExceptionCatch
_errMessage =
"An IO exception was thrown while trying to write file [" & RemotePath & "] - " & ioEx.Message--------------- End of Code ----------------------
Please note that this happening for the MoveTo function as well!!!
Thanks again for any help.
Cheers
Right so my testing goes on and apparently, which i didnt' notice before but under the properties window of the file i was trying to copy/move (right clicked on the file from windows explorer) it said something like the file has been received from a remote computer and the security is blocked.
After selecting the unblock command it now transfers fine.
Can anyone shed any light on this blocking/unblocking feature cause it's news to me.
Cheers
Cam
I feel like I'm talking to myself here
but as I've run into this problem a couple of times I've unearthed some more information that will hopefully help someone else out and not have to suffer through this!Windows XP SP2 and Windows 2003 (and I imagine above) have introduced a new file mechanism called ZoneIdentifiers - which I can only assume (due to lack of documentation) is another shot fired by Microsoft in the battle against viruses/worms etc. that seems to block files that have originated from a remote location from being copied without express constent from the user.
The problem as I see it though is that the ZoneIdentifiers are buggy, to say the least, and files that we've created and copied around our local machines have been block by the OS. Some that have been passed around the domain have been blocked as well (blocking these files down are debatable to say the least).
So for those of you encountering the above problem where a FileCopy (via .NET) is not transferring the file and are getting the message "The operation completely successfully" have a look to see if the source file has been blocked. If so unblock them and try again.
If, in code, you need to unblock them please refer to http://www.jameskovacs.com/blog/PermaLink.aspx?guid=6985963b-3d85-41ae-bca8-5f9efe2a79c7 for a utility (including .NET source code) to remove the ZIs.
Hope this helps someone, somewhere :)
Cheers
Cam Church


