web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Dot Net Framework in NAV2017 - How to use Functions of two Classes?

(0) ShareShare
ReportReport
Posted on by

Hello Community

I am very new to use dot Net in MS Dynamics NAV, and I am still at the begining.

So I want to use Dot Net to check if any file exists in a directory (I know you can do this with C/AL too, but I would like to use the dot Net method)

So my C# code looks like this:

bool isEmpty = !Directory.EnumerateFiles(path).Any();



In MS Dynamics NAV 2017 I declared a Local Dot Net Variable called DirectoryL with subtype System.IO.Directory.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
I wrote this code:

IsEmpty := DirectoryL.EnumerateFiles(DirectoryPathP).Any();



And I get the Error message "You have specified an unkown Variable: any"

I know that the any functions is from the System.Linq.Enumerable.'System.Core but how do I combine functions of two dot net classes in one statment?
So my question is how do I use this C# statment in dynamics NAV?

Thanks for your suggestions.
Regards Joshua





*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    You cannot use LINQ statement in C/AL. You need to separate the instructions or use Directory.GetFiles method:

    msdn.microsoft.com/.../07wt70x2(v=vs.110).aspx

    However, codeunit FileManagement (419) has all the instructions for what you need and it's recommended to use that also for future portability.

  • Community Member Profile Picture
    on at

    Hi Stefano

    Thanks alot for your answer and the hint to codeunit 419 this was very helpful and I will look into it. Is there any documentation about the different functions in this codeunit and how to use them?

    For the info about LINQ, is there a general rule which classes/functions can not be used in C/AL?

    And just for my understanding could you maybe make a quick example, how I would write my C# statement in C/AL with seperate instructions (2 .net variables)? So I would know for the future if I had to use functions that are from 2 different classes.

    Thank you again for your help!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans