UPDATE: Copy file from serverA to serverB

Gee picture Gee · Nov 14, 2012 · Viewed 11.3k times · Source

Okay just spoke to our server admin and both servers have all permissions set. Now I get an error: The network path was not found. I gave it dummy server names for this demo am I using the wrong names. Should I tried using the IP addresses and still get this error. What am I doing wrong?

'File.Copy("\\sever.name.local.mil\pdf\audits\2009-05-19audit-09-01.pdf", 
 "\\sever.name.remote.mil\sigar_cms\pdf\audits\2009-05-19audit-09-01.pdf")'

Can someone give me some suggestions, this is recking my brain.

Thanks

Answer

Jacob picture Jacob · Nov 14, 2012
Dim FilePath As String = "\\sigar" & "\pdf\audits\" & ""

This will create the string \\sigar\pdf\audits\. You could simplify the line to be:

Dim FilePath As String = "\\sigar\pdf\audits\"

Server.MapPath is used to translate a virtual path in your web site to what the file path is on the server. In other words, you don't need to use it at all. Change your second line to:

FileUpload1.SaveAs(FilePath + FileName)

If that isn't working, then it may be that the identity that your application pool is running under does not have permissions to write a file in the specified path. Try adjusting the share and/or file permissions on sigar.

Update

To just copy a file, use File.Copy:

File.Copy("\\serverA\path\to\file", "\\serverB\path\to\file")