Friday, January 9, 2015

Checking if a Directory Exists - Microsoft Dynamics NAV

Hi All,

Check directory exists or not in Dynamics NAV
It will first check for server/shared directory and if directory doesn’t find than it will check for local directory








 
Name
DataType
Subtype
Length
SystemDirectoryServer_lDnt
DotNet
System.IO.Directory.'MSCORLIB'

SystemDirectoryLocal_lDnt
DotNet
System.IO.Directory.'MSCORLIB'


Set the RunOnClient = YES for local directory dotnet variable

















ValidateDirectoryPath_lFnc(FileDirectory_iTxt : Text[250]) : Boolean
{
IF SystemDirectoryServer_lDnt.Exists(FileDirectory_iTxt) THEN  //First check for server directory
  EXIT(TRUE)
ELSE IF GUIALLOWED THEN BEGIN                                  //After check for client directory (Note: Not working for NAS)
  IF SystemDirectoryLocal_lDnt.Exists(FileDirectory_iTxt) THEN
    EXIT(TRUE)
END ELSE
  EXIT(FALSE);

}

2 comments:

  1. Hi Nilesh,

    I tried to repeat your code in my installation of NAV2016 but I just can't find the "System.IO.Directory" .NET component that you state in your example. All I've got are two "System" assemblies (v2 & v4) with no ".Directory" type or the "System.IO" Assembly with no types at all. Am I missing something?
    Thanks in advance - Richard.

    ReplyDelete
    Replies
    1. rhrazno,
      You should declare your variable with dotnet type and then choose "mscorlib" assembly and then "System.IO.Directory"

      Ypu can have a look at codeunit 419 - File Management, there are functions that might help you

      Delete