putfile error

I am having trouble writing files to the controller. I think I am following the examples correctly. The error I get for a putfile call is GenericControllerException “File Not Found on the local filesystem”. What am I missing here?

Here is my code:

Try

Dim LocalFile As String = AFileSystem.LocalDirectory + “” + “test.txt”

Dim RemoteFile As String = AFileSystem.RemoteDirectory + " est.txt"

master = Mastership.Request(controller.Rapid)

AFileSystem.PutFile(LocalFile, RemoteFile)

Catch ex As Exception

MsgBox(ex.ToString)

Eny Try

If you expand the values of LocalFile and RemoteFile, what are they? Do they match the location of the source and destination on your PC?

Yes, that was the first thing I checked. The paths are fine and the file really does exist.

Try the following snippet; it works on my machine.

It appears that there are some problems with trying to use LocalDirectory or RemoteDirectory to form your paths. You may wish to avoid using LocalDirectory at all as I have done below; this seems to be the source of your problem. I’m not sure that LocalDirectory really means anything on PCSDK; however it does refer to the TEMP directory for the FLexPendant and is definitely used there.

NOTE: if you comment out the line where we set the value of LocalDirectory, the code should fail with the same exception that you reported above.

You can use a dialog control to browse for the file you wish to transfer, then you might try to modify the value of RemoteDirectory to change the destination. It appears that value of RemoteDirectory is appended to the destination argument in PutFile.

If anyone can clarify the proper usage here, it would be appreciated.

Private Sub PutFiles()

Dim strPath As String

Dim ms As Mastership

Try

If ms Is Nothing Then

ms = Mastership.Request(ctrl.Rapid)

Else

ms.Release()

ms.Dispose()

ms = Nothing

ms = Mastership.Request(ctrl.Rapid)

End If

strPath = “C: emp abtest.prg”

ctrl.FileSystem.LocalDirectory = “”

ctrl.FileSystem.RemoteDirectory = “(HOME)$”

ctrl.FileSystem.PutFile(strPath, System.IO.Path.GetFileName(strPath))

Catch ex As Exception

MsgBox("Exception text: " & ex.ToString(), MsgBoxStyle.OKOnly, “Exception”)

Finally

If Not ms Is Nothing Then

ms.Release()

ms.Dispose()

ms = Nothing

End If

End Try

End Sub

Great, that works. Thanks.