Client-side .NET components are executed on the client computer. Usually, these are components for user interaction, user interface, or parts of the application interacting with the software installed on the client computer.
In the following example, we will develop a document storage where the user can upload Word documents and open files to edit from the storage. MS Word is installed on the client computer and is controlled by a client-side .NET components.
Field No. |
Field Name |
Data Type |
Length |
1 |
ID |
Integer | |
2 |
File Name |
Text |
250 |
3 |
Document |
BLOB |
Editable
property to No.NewDocumentItems
to ActionItems
and insert two actions in the container: Import
and Edit
.
Name |
DataType |
SubType |
FileManagement |
Codeunit |
File Management |
Import - OnAction
trigger:
Name |
DataType |
SubType |
FileStorage |
Record |
File Storage |
ClientFileName |
Text | |
ServerFileName |
Text |
Import - OnAction
trigger opens a file dialog that prompts the user to choose a file to import. If the file is selected, it is uploaded to the server and saved in the File Storage table:ClientFileName := FileManagement.OpenFileDialog('File to import','', 'MS Word documents (*.doc, *.docx)|*.doc;*.docx,'), IF ClientFileName = '' THEN EXIT; ServerFileName := FileManagement.UploadFileSilent(ClientFileName); FileStorage."File Name" := ClientFileName; FileStorage.Document.IMPORT(ServerFileName); FileStorage.INSERT; FileManagement.DeleteServerFile(ServerFileName);
Edit - OnAction
trigger performs the backward operation. The file stored on the server must be downloaded to the client and opened by the MS Word application. There should be a single local variable in the trigger, ClientFileName
of the Text
type:IF NOT Document.HASVALUE THEN EXIT; ClientFileName := BLOBExport(Rec); ClientFileName := OpenEditWordDocument(ClientFileName); IF CONFIRM('Do you want to import the modified document?') THEN BLOBImport(Rec,ClientFileName); FileManagement.DeleteClientFile(ClientFileName);
OpenEditWordDocument
. It has one Text
type parameter, ClientFileName
. The return type is also Text
.
Name |
DataType |
Subtype |
WordApp |
DotNet |
Microsoft.Office.Interop.Word.ApplicationClass |
WordHelper |
DotNet |
Microsoft.Dynamics.Nav.Integration.Office.Word.WordHelper |
WordHandler |
DotNet |
Microsoft.Dynamics.Nav.Integration.Office.Word.WordHandler |
WordDocument |
DotNet |
Microsoft.Office.Interop.Word.Document |
ErrorMessage |
Text |
RunOnClient
property. It must be Yes for all variables.OpenEditWordDocument
:WordApp := WordHelper.GetApplication(ErrorMessage); IF ISNULL(WordApp) THEN ERROR(ErrorMessage); WordHandler := WordHandler.WordHandler; WordDocument := WordHelper.CallOpen(WordApp,ClientFileName,FALSE,FALSE); WordDocument.ActiveWindow.Caption := "File Name"; WordDocument.Application.Visible := TRUE; WordDocument.Activate; EXIT(WordHandler.WaitForDocument(WordDocument));
Documents are stored in the table designed in the first three steps of the recipe. But the files are edited on client computers and uploaded to the server from the client side. Here we need to take care of client-server interaction and involve client-side .NET components.
Functions for file exchange between client and server are implemented in codeunit 419
File Management.
A global variable referencing this codeunit
is declared in Step 8. We later employ this codeunit
in Step 10 to display the file selection dialog to the user:
ClientFileName := FileManagement.OpenFileDialog
The selected file is located on the client box, now it has to be uploaded to the server where it will be imported to the storage table. This is done by the UploadFileSilent
function in the FileManagement
codeunit:
ServerFileName := FileManagement.UploadFileSilent
Client-side .NET activities are concentrated in the OpenEditWordDocument
function. A document stored on the server is downloaded to the client computer and sent to the application that will open and process it. Note that all .NET variables in the function must be running on the client. If any of the interacting .NET classes are instantiated in the server process, while others are on the client side, this will result in a runtime serialization error.
3.15.214.155