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 AX (Archived)

Import file on network in Batch job

(0) ShareShare
ReportReport
Posted on by 935

Hi,

I have a batch job that will import a file. The import file is saved in a different server (not where the AOS resides). The batch job runs if I just use a directory where the AOS is installed. Also, if I run the class manually (not as batch job) and I use a network directory, I can import the file successfully. 

Any ideas?

Thanks

*This post is locked for comments

I have the same question (0)
  • Bilal Issa Profile Picture
    4,370 on at

    Hi,

    can you please write the error you are getting?

    Regards,

    Bilal

  • Freya Tan Profile Picture
    935 on at

    I don't get any error. The batch job succeeds. But the problem, it never execute the file in the directory.

  • dolee Profile Picture
    11,279 on at

    Check the network folder access right, Make sure AOS service account can access the network folder.

    Then try again with the network folder setup.

  • Bilal Issa Profile Picture
    4,370 on at

    Hi,

    can you please let me know the code you are using?  are you using WinAPISerevr, or something else?

    Regards,

    Bilal

  • Freya Tan Profile Picture
    935 on at

    I'm using System.IO not WinAPIServer.

  • Bilal Issa Profile Picture
    4,370 on at

    so are using the following code?

          filepermission = new FileIOPermission(fileName, 'R');

           interopPermission = new InteropPermission(InteropKind::ClrInterop);

           permissionSet = new Set(Types::Class);

           permissionSet.add(interopPermission);

           permissionSet.add(filepermission);

           CodeAccessPermission::assertMultiple(permissionSet);

            System.IO.File::Move(fileName,newFileName);

           CodeAccessPermission::revertAssert();

  • Freya Tan Profile Picture
    935 on at

    I'm getting the file list from the directory first. My method looks like:

    // loop all files that fit the required format

       InteropPermission   interopPerm;

       System.Array        files;

       int                 i;

       container           fileList;

       ;

       interopPerm = new InteropPermission(InteropKind::ClrInterop);

       interopPerm.assert();

       files = System.IO.Directory::GetFiles(@_sourceDirectory, #FileExtension);

       for( i=0; i<ClrInterop::getAnyTypeForObject(files.get_Length()); i++ )

       {

           fileList = conins(fileList, conlen(fileList)+1, ClrInterop::getAnyTypeForObject(files.GetValue(i)));

       }

       return fileList;

    Then I loop on the container to process each file. I open the file and assign it to a CommaIo. My code looks like:

    boolean openFile(Filename   _fileName)

    {

       boolean     ret = true;

       ;

       csvFile = null;

       csvFile = new CommaIo(_fileName, #io_read);

       if(!csvFile)

       {

           //Error when opening file

           ret = checkFailed("@SYS69639");

       }

       return ret;

    }

  • Bilal Issa Profile Picture
    4,370 on at

    please try to use the follwoing code to get the files list.

       System.IO.DirectoryInfo     directory;

       System.IO.FileInfo[]        files;

       System.IO.FileInfo          file;

       InteropPermission           permission;

       str         fileName;

       counter     filesCount;

       counter     loop;

       container   mathchingFiles;

       ;

       permission  = new InteropPermission(InteropKind::ClrInterop);

       permission.assert();

       directory   = new System.IO.DirectoryInfo(_folderPath);

       files       = directory.GetFiles(_filePattern);

       filesCount  = files.get_Length();

       for (loop = 0; loop < filesCount; loop++)

       {

           file            = files.GetValue(loop);

           fileName        = file.get_FullName();

           mathchingFiles  +=  fileName ;

       }

       CodeAccessPermission::revertAssert();

       return mathchingFiles;

  • Shiva0414 Profile Picture
    30 on at

    Hi  Freya Tan

    I'm trying to export my data to CSV via batch processing and facing errors, my code work in client side but not on Batch, Have you got any solution?

    Thanks

  • dolee Profile Picture
    11,279 on at

    Hi Shiva,

    When code is running in batch, they are most likely running on server. Make sure the AOS service account has proper folder rights and the path you specified is in UNC network path.

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 AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans