Browsing for a file
In the first recipe of this chapter, we saw how to use HYPERLINK
to open an external file in an appropriate application; in this recipe, we will see how to use an NAV out of the box codeunit to select a file using a dialog box.
How to do it...
First create a new codeunit from Object Designer and follow the steps.
Then add the following global variables:
Name
Type
Subtype
Length
FileMgt
Codeunit
File Management
SelectedFile
Text
255
Next, write the following code in the
OnRun
trigger of the codeunit:SelectedFile := FileMgt.OpenFileDialog('NAV File Browser','*.txt',''); MESSAGE('You selected %1', SelectedFile);
Finally, save and close the codeunit.
How it works...
To carry out file handling activities, NAV provides a codeunit 419
(File Management
). It uses .NET
interoperability, which allows using the function of the .NET
library. The OpenFileDialog
function of this codeunit allows us to open a simple dialog box in Open mode. This function takes three parameters...