Question

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

Was it helpful?

Solution

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")

OTHER TIPS

SOLVED: I figured it out. I was suppose to use the network path same one used to map a drive. Forgot to use $ dollar sign.

 ''# Save files to disk
  FileUpload1.SaveAs(Server.MapPath("../pdf/audits/" & FileName))

 ''# Local Path
  Dim localPath As String = "\\localserver\folder$\pdf\audits\"

 ''# Remote Path
  Dim remotePath As String = "\\remoteserver\folder$\pdf\audits\"

 ''# Copy from Local to Remote servers
  System.IO.File.Copy(localPath + FileName, remotePath + FileName)

There are several things wrong with the posted code. If you have more code, I would recommend posting it. With that said, based on what I see, reading this MS article will answer your question--as it is currently expressed.

Write a text file (Basic File IO)

This sample code uses a StreamWriter class to create and write to a file. If you have an existing file, you can open it in the same way.

Dim writer As StreamWriter = _
New StreamWriter("c:\KBTest.txt")
writer.WriteLine("File created using StreamWriter class.")
writer.Close()

Assuming the two servers are on the same local network and you have the appropriate access, you should be able to use the File.Copy method and use the UNC for each server/path.

If the situation is a bit more complex than simply copying a file between two peer servers, you may want to consider using FTP or SSH as a transport method.

Since your tagging , I'm assuming that this in a web application running under an application pool in IIS.

Your first step is to ensure your app pool user account has write permissions on your other account. By default this account is something like IIS_USR.

The second step is to save the file to the second server.

Dim FilePath As String = "\\sigar\pdf\audits\"
Dim FileName As String = "MyFile.txt"

FileUpload1.SaveAs(String.Format("{0}{1}",FilePath, FileName))

You could also create your own write method

Dim SourcePath As String = "C:\foo\pdf\audits\"
Dim FileName As String = "MyFile.txt"

Dim FileToCopy As String = String.Format("{0}{1}",SourcePath, FileName)

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

System.IO.File.Copy(FileToCopy, DestPath)

@Gee I adapted your code to copy from one place on a server to another place on that same server. this code worked. Do this first in your environment--just to be certain.

It seems to me that it is some kind of network access issue. Cross domains, user or group permissions or restrictions, etc.

Imports System.IO
File.Copy("\\CHI-CSD-06.mycompany.local\temp1\testfile.txt", "\\CHI-CSD-06.mycompany.local\temp2\testfile.txt")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top