D365 Finance & Operations and Dynamics AX Forum

 View Only
  • 1.  AX Class to monitor a network folder for a file

    SILVER CONTRIBUTOR
    Posted Oct 12, 2021 09:20 AM
    Hi all,

    I have a need to develop a class in AX 2012 that will monitor a named network UNC folder for a CSV file that will be read and then moved to an archived folder. This class will run as a batch job, scheduled to run every hour.

    Has anyone ever done this and can help me? Any pointers would be very much appreciated

    Regards,
    Paul
    #AX2012#Technical #Intermediate 
    ​​​​

    ------------------------------
    Paul Fildes
    AX Technical Support Consultant
    Steelite International Ltd
    Stoke-On-Trent
    ------------------------------


  • 2.  RE: AX Class to monitor a network folder for a file

    Posted Oct 13, 2021 08:40 AM
    Hello Paul,

    When I read your post I hear a chant for FileSystemWatcher in my head

    The FileSystemWatcher class in the System.IO namespace can be used to monitor changes to the file system. It watches a file or a directory in your system for changes and triggers events when changes occur.  FSW monitors for Changed, Created, Deleted, Error and Renamed events. Check out the Created event. You can find a Visual Studio C# FileSystemWatcher project that you can deploy as a service to test the functionality.  You can define what file extension you will monitor for in the parent and also child folders

     https://docs.microsoft.com/en-us/dotnet/api/system.io.filesystemwatcher?view=net-5.0

    Here is a gent trying to making it work in AX, but the problems he is experiencing is why I often will create a FSW service on a server doing the heavy lifting and let AX receive from the FSW service. Last time I did this in .Net I remember when my file was created on the server it spawned two Created event, not one.  If you see his code is commented for the changed event and IIRC changed spawned 27 consecutive event.

    https://philippsen.wordpress.com/2010/10/25/filesystemwatcher-problem-file-is-in-use-by-another-process/

    Enjoy, nice requirement

    ------------------------------
    Bob Coward
    Dynamics AX/F&O Developer
    DSG
    Grayson GA
    ------------------------------



  • 3.  RE: AX Class to monitor a network folder for a file

    SILVER CONTRIBUTOR
    Posted Oct 14, 2021 03:33 AM
    Hi Bob,

    Thanks for your reply to my question. I have never dabbled with Services so this is new to me. I will take a look and hopefully it will help with my problem.

    Its quite an interesting task to investigate. Reading a file of sales line data, reserving the requested quantities and setting the ActivateNow (SalesDeliverNow) value.

    Thanks and regards,
    Paul

    ------------------------------
    Paul Fildes
    AX Technical Support Consultant
    Steelite International Ltd
    Stoke-On-Trent
    ------------------------------



If you've found this thread useful, dive deeper into User Group community content by role