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

  • Community Member Profile Picture
    on at
    RE: Dot Net Framework in NAV2017 - How to use Functions of two Classes?

    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!

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Dot Net Framework in NAV2017 - How to use Functions of two Classes?

    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.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics NAV (Archived)

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans