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)

best practice to run an external program from NAV codeunit

(0) ShareShare
ReportReport
Posted on by 5,136

Hello experts! I was wondering if you can help guide me in trying to run an exe file (.net) I wrote from within NAV.  First of, where is the best place to store this exe file?  Should I store it in the APPLICATIONPATH\addins folder?  If so, does this mean I have to distribute this exe file in each RTC workstation?

Secondly, I am not sure if I am doing this correctly.  I am using System.Diagnostics.Process to run this program from within my codeunit.  see below.

....
CLEAR(process);
process := process.Process();
process.StartInfo.UseShellExecute := FALSE;
process.StartInfo.FileName := ConvertProgPath;
process.StartInfo.Arguments := InputXMLPath + ' -xsl ' +  XSLTPath + ' -output ' + OutputFilePath;
process.StartInfo.CreateNoWindow :=TRUE;
process.Start();

process.WaitForExit();  //tells Nav to wait for the program to close

But it doesn't seem to work.  I am erroring out.    it says it doesn't know where the file is.  I stored the exe file in the c:\program files\Microsoft dynamics nav\70\service\addins folder.  But when I check if it exists, it says it doesn't.  see below code snippet whereby it will error out.

  ConvertPDFPath := APPLICATIONPATH + 'addins';
  ConvertProgPath := ConvertPDFPath + '\myprogram.exe';

  IF File.EXISTS(ConvertProgPath) THEN
     message('%1 EXISTS!',ConvertProgPath)
  ELSE
     ERROR('%1 DOES NOT EXIST!',ConvertProgPath);

But If I run the program using the start-run (outside of nav) it works!

Thoughts?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Andrey Baludin Profile Picture
    3,941 on at

    Hi!

    I use next construction, where Process is System.Diagnostics.Process dotnet variable:

    It's a codeunit which runs by job queue and takes file name and arguments from job queue entry parameter string (they separate by ; symbol). RunOnClient property of dotnet variable should be = No in this case.

    app2.JPG

    Also you can use universal function with path and attributes parameters for running any app:

    app2.JPG

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