At first, the file handling dual behavior in a Thinfinity® VirtualUI web-enabled application can appear to be a bit confusing for new developers and users who are accustomed to running the application from the desktop. It’s actually pretty simple, as you will see in this article.
Previously, we shared with you a brief summary of the file handling possibilities in Thinfinity® VirtualUI apps. In this opportunity, we will try to shed some light on this topic and show you how to upload remote files in web-enabled applications.
Getting Files from the Browser
A VirtualUI web-enabled application has the ability to open files from its application environment, as usual, by using the standard file system dialog. But if the developer sets VirtualUI.StdDialogs to false, when a user calls the application from the browser and wants to open a file, a special dialog box will appear to allow a file upload.
Why upload remote files and not open them?
When you use a web-enabled application from the browser, the communication is enabled through a server application: the Thinfinity® VirtualUI Server. In this way, you are actually using the app remotely, from the Web.
So, when you need to select a file located in the browser’s device to be read by the application, you need to do a file upload in order to send a file from the browser environment to the web-enabled application, which is running in the VirtualUI Server.
Activating the remote file mode
In order to activate the file upload, the developer has to set the VirtualUI.StdDialogs (for standard dialogs) attribute to false.
VirtualUI.StdDialogs := false;
To go back to using the standard Windows File Open dialog and do a common file open on the application machine or local network, the developer has to set this attribute to true. If you do this, the remote file upload will be deactivated.
Where is the uploaded file?
By default, the uploaded files are stored automatically in a public server folder (i.e. C:\Users\Public\Documents\Cybele Software\Thinfinity\VirtualUI\). Developers can retrieve uploaded files from this folder in order to handle them.
But if the developer wishes to use a different folder, Thinfinity® VirtualUI has additional ways to upload files to any other destination.
Changing the destination folder
The VirtualUI class has an event method called OnGetUploadDir which is fired during an upload request, allowing you to change the save folder.
This Delphi example shows how to define it:
procedure TMyForm.MyGetUploadDirHandler(Sender: TObject; var Directory: string; var Handled: Boolean); begin Handled := True; Directory := ExtractFilePath(Application.ExeName); End; ... ... VirtualUI.OnGetUploadDir := InternalGetUploadDir;
Another way to upload remote files
The VirtualUI class has an additional method to upload files from the browser. This method is:
Where virtualui is an instance of the VirtualUI class. This method allows you to upload files from browsers and store them in a selected folder. The UploadFile method is independent of the StdDialogs attribute status and, of course, it is not available when the application is used in desktop mode.
How to change the folder
If you have the need to change the destination folder, you may use the event: ‘onUploadEnd’
Find an example here (zip file).
Nowadays, the Web imposes many necessary security measures which end up limiting the use of web-enabled applications. Thinfinity® VirtualUI manages to integrate remote file handling securely, allowing the user to perform typical operations seamlessly.