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

  • 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
    Stefano Demiliani 37,162 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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,403 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans