How Do I Transfer Files Between the Server and the Client Machine? (Magic xpa 2.x)
In Rich Client programming, the programmer needs to keep in mind that there are always two operating system environments to work with: one on the server, and one on the client. Sometimes it is more efficient to have files in one place rather than the other, and you will need to explicitly move the files.
Magic xpa provides a number of resources to handle files on the two machines, where you can specify the location of the file as being on either the client or the server. Two of these are specifically for transferring files: ServerFileToClient() and ClientFileToServer().
In this example, a file is sent from the server to the client. The image on the left is displayed from the server, the one on the right, from the client.
As a programmer, you have control over where the server file is located. However, you do not have control over the client computer.
When the Do Transfer button is pressed, the ServerFileToClient() function is called. This transfers the file to the client, to a location that is under the control of Magic xpa, and returns the file name (and thus location) to the program.
When the end user wants to send a file to the server, the file name is known at the client side.
Often the end user will be choosing which file to send. In this example, we provided a zoom button that uses the ClientFileOpenDlg() function to select the file.
Then, the file name is parsed to strip off the directory path, using Flip() and StrToken():
Flip(StrToken(Flip(Trim(A)),1,'\'))
This results in the string ‘Cat.bmp’, in this case, which is concatenated with a logical representing the final server location. This way no locations are hard-coded.
Finally, the ClientFileToServer() function is used to transfer the file. The return code can be used to give the end user an error message if the transfer didn’t work.
The Rich Client Samples project (program RRC09)