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

exception while copying a file to a network drive

P: n/a
I using the routine below to copy file to a network drive for a regular
backup process. Before calling this routine I using another function to check
the presence of the LAN connection and the server where the network drive
exists.
Although of this check I am sometimes getting an exception (in 5% of
times)saying "Could not find the U:\...\File.ext" or part of its path"
Although the network dirve is available and accessible by windows explorer
and the path is correct and
existing.
I would apreciate if some one can help troubleshooting this unexpected and
non understandable error.

Private Sub CopyFile(ByVal DstBasePath As String, ByVal SrcFileInfo As
FileInfo)
Try

Dim strDstFile As String = DstBasePath &
SrcFileInfo.FullName.Substring(2)

Dim DstFileInfo As New FileInfo(strDstFile)
If DstFileInfo.Directory.Exists = False Then
DstFileInfo.Directory.Create()
End If

Me.c_Status = String.Format("Copying {0}{1}To {2}", SrcFileInfo.Name,
vbCrLf, DstBasePath)

Me.c_Progress += 1

Me.c_FCD_Status.Invoke(SrcFileInfo.Name, Me.c_Progress, Me.c_Status,
True)

If DstFileInfo.Exists = False Then
SrcFileInfo.CopyTo(DstFileInfo.FullName)
ElseIf DstFileInfo.LastWriteTime <> SrcFileInfo.LastWriteTime Then
SrcFileInfo.CopyTo(DstFileInfo.FullName, True)
End If

Catch exIO As IOException

Catch ex As Exception

End Try

End Sub
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi

Looking through your question. Please tell me the answers to these
questions:

1) What is c_Status?
2) What is c_Progress? I think an Integer, but why are you using this if you
aren't using a recursive copy?
3) What is c_FCD_Status?
4) Is youe U:\ drive original or destination directory?
5) Have you tried an UNC path instead? Example: \\MyServer\MyPath etc.
6) Why are you creating a directory based on the filename?
7) Do you have to use FileInfo instead of a string for the srcFileInfo?
8) What file permissions are you using to copy a file over a network drive?

Awaiting your answers

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #2

P: n/a
Thank you for your time looking at my question. Here's the answers:
1- c_Status is string e.g. "Copying xxx.yyy to c:\dstDir"
2- c_Progress is integer and it is used because the routine is recuresive
it's called with a loop in another routine.
3- c_FCD_Status is "Private c_FCD_Status As FileCopierStatus" where
FileCopierStatus is "Delegate Sub FileCopierStatus(ByVal FileName As String,
ByVal Progress As Integer, ByVal strStatus As String, ByVal Status As
Boolean)"
4- "U:\" is the distination directory and it's a mapped drive. On our
network there is a personal network drive for each user that is noly
accessible by the user only and mapped to "U:"
5- I have not try the UNC because the network drive is mapped on every
target machine as said the previous point.
6 & 7- are not clear form. What's the point?
8- I don't use a file permession to copy the file over the network, because
the user is having full control over his network personal drive "U:\" see
note: 4

Just to clarify When run this routin 100 times it gives the error message on
about 5 times out of the 100. So it's working fine but for know reason it
gives the exception "Couldn't find path U:\...\file.xxx" which means there's
a problem to access the destination file.

Also it could help if I mentioned this error is happening at the CopyTo
method of the FileInfo class, so you can forget about other lines in my code
because there a many other detatils that can not be given in such short note

Thanks in advance.

"Crouchie1998" wrote:
Hi

Looking through your question. Please tell me the answers to these
questions:

1) What is c_Status?
2) What is c_Progress? I think an Integer, but why are you using this if you
aren't using a recursive copy?
3) What is c_FCD_Status?
4) Is youe U:\ drive original or destination directory?
5) Have you tried an UNC path instead? Example: \\MyServer\MyPath etc.
6) Why are you creating a directory based on the filename?
7) Do you have to use FileInfo instead of a string for the srcFileInfo?
8) What file permissions are you using to copy a file over a network drive?

Awaiting your answers

Crouchie1998
BA (HONS) MCP MCSE

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.