Fetch Filename from Directory using DotNet Datatype-NAV 2017

During recent implementation got task to fetch the files from specified directory to import in tables using XMLPORT and I was using NAV 2017.

Now in classic version we were able to use FILE and this virtual table was giving us the list of files in specified path by using required filters and we were able to import data from multiple files.

Coming to latest version to find the files in directory I used DotNet variables as follows

From one of the folder I am fetching the filename as follows

folder1

Define the variables as follows

Name             Data Type               Sub type                                                       Length
gvDirectory  DotNet                      System.IO.DirectoryInfo.’mscorlib’
gvFile             DotNet                      System.IO.FileSystemInfo.’mscorlib’
gvArr              DotNet                       System.Array.’mscorlib’
i                        Integer

In one codeunit write following program

gvDirectory:=gvDirectory.DirectoryInfo(‘E:\WorkingFolder\Target\’);
gvArr:=gvDirectory.GetFileSystemInfos();
FOR i:=0 TO gvArr.Length-1 DO
BEGIN
gvFile:=gvArr.GetValue(i);
Name:=gvFile.Name;
END;

Message(Name);

 

message

 

This will help in importing the multiple/sequential’s files in tables using XMLPORT.

Let me know yours feedback.

Cheers

 

Advertisements

3 thoughts on “Fetch Filename from Directory using DotNet Datatype-NAV 2017”

  1. Hi,
    I’d do it the following way:

    Variables:
    DirectoryInfo DotNet System.IO.DirectoryInfo
    ArrayList DotNet System.Collections.ArrayList
    FileName Text

    Code:

    DirectoryInfo := DirectoryInfo.DirectoryInfo(‘MySearchPath’);
    ArrayList := DirectoryInfo.GetFiles(‘*.txt’); //Example filter on txt files only
    FOREACH FileName in ArrayList DO BEGIN
    MESSAGE(FileName);
    END;

    So we do not need to use a DotNet File Variable.

    Another point: I would not recommend to use a prefix like “gv”, this is not Microsoft Styleguide compatible.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s