Monday, August 8, 2016

Create New Directory using Dynamics NAV C/AL Code

Hello Friends,

Use the following code to create the new directory (folder) using Dynamics NAV C/AL Code.












    PROCEDURE CreateNewDir_gFnc@33027956(OldFilePath_iTxt@33027923 : Text;NewDirectoryName_iTxt@33027924 : Text[50];VAR AttDir_vTxt@33027927 : Text);
    VAR
      DirectoryHelper@33027920 : DotNet "'mscorlib'.System.IO.Directory" RUNONCLIENT;
      directory@33027921 : Text;
      FileMgt_lCdu@33027922 : Codeunit 419;
      PathHelper@33027925 : DotNet "'mscorlib'.System.IO.Path";
      SystemDirectoryServer_lDnt@33027926 : DotNet "'MSCORLIB'.System.IO.Directory";
    BEGIN
      // Get the directory from the OldFilePath, if directory is empty it will just use the current location.
      directory := FileMgt_lCdu.GetDirectoryName(OldFilePath_iTxt);

      NewDirectoryName_iTxt := DELCHR(NewDirectoryName_iTxt,'=','#%&*:<>?\/{|}~');

      // create the sub directory name is name is given
      IF NewDirectoryName_iTxt <> '' THEN BEGIN
        directory := PathHelper.Combine(directory,NewDirectoryName_iTxt);

        IF NOT SystemDirectoryServer_lDnt.Exists(directory) THEN
          DirectoryHelper.CreateDirectory(directory);
      END;

      AttDir_vTxt := directory;
    END;


Download the sample code at following location:
https://1drv.ms/t/s!An8nhANnLJmtiS-A90kgwaGLFlPC

Thank you for reading.
I wish it will help you in future.

Please write a comment here if you need any help.

Keep Sharing...Keep Growing....

No comments:

Post a Comment