Writing from NAV to Azure Storage

CraigSCraigS Member Posts: 5
I have an NAV implementation which is running on an Azure VM. I am writing out files to the server which are then ftp'd to a 3rd party warehouse.

I need users to be able to view and move these files from their local machines. So basically I need a file share which is accessible from both the server and the client pc.

The server and the client pc's are not on a shared domain. I thought I had a reasonably elegant solution in that I could create a file share using an Azure storage account. A "net use" function allows me to create a share on the server and also on the users pc's. This works very well and users can see directories and files in this share.

However, NAV does not seem to be able to write out to this directory. When I call MyFile.CREATE(.....) I simply get a "Could not find a part of the path 'F:\Warehouse\Outbound\SORD_SO00412.xml'." if I map the drive, or "I/O Error" if I use a UNC path.

I appreciate that this is likely due to the fact that this is not a "normal" windows directory. Has anyone manged to write to such a directory and have sample code they could share?



  • JuhlJuhl Member Posts: 700
    Magicpath is your friend. See File Management CU, think it's 419, can't remember.
    It's used to transfer files between windows client and service tier.
    Follow me on my blog juhl.blog
  • CraigSCraigS Member Posts: 5
    edited 2017-05-18
    Thanks Juhl. Unfortunately I don't think that is the answer. The issue I have is not writing from server to client or vice versa. I want the files to be written to a directory on the NAV server which is where the ftp process will pick them up and move them off site. I want users to be able to access that directory via a share in case they need to move files from an error directory to a processing directory. Doing this via a network share is preferable to them having to log onto the NAV server to do it.

    Using an Azure shared directory for this works perfectly - except, I cannot write from NAV to this directory which is based on Azure storage.
  • JuhlJuhl Member Posts: 700
    All fileaccess happens on the server, so what ever you program for the clients to use, will point at the server.
    Make a page fill it with file-list and make actions to move or whatever using .Net.

    Think you are overthinking/looking how easy this could be.

    I always stream files from memory direct to ftp, without touching the file system.
    Follow me on my blog juhl.blog
  • EvREvR Member Posts: 178
    You could easily upload the files to azure blob storage using the .net api provided by Microsoft, and save the url to the nav record instead of the UNC path. That's what I've been doing for years and it hasn't failed me yet.
  • JuhlJuhl Member Posts: 700
    edited 2017-05-19
    EvR is right.
    But all this is crossing the river to get water.
    Create the data in memory using streamwriter. Send the stream to ftp instead of saving to file first.
    All this can be done with standard .Net.
    No need for ever using the file system to send a file to ftp server!
    Follow me on my blog juhl.blog
  • EvREvR Member Posts: 178
    edited 2017-05-22
    I think the world has moved on from FTP :)
    The great thing about Azure blob storage is that it's dirt-cheap and requires no maintenance and backups.
    Using the azure api won't require you to save it to a file either. Just transfer a byte[] directly (or base64 encode it from memory).
  • pradipradi BrusselsMember Posts: 15
    HI @craig.s did you find a solution to write a file in Azure storage directory. I too need to write a file and facing the same issue.
  • GabMemGabMem Member Posts: 2
    For future lost souls\readers of this post - as today I faced the same problem:
    • If you can use just the API as suggested above, it's better.
    • If you are in a Azure region where you can use Azure File Sync, it may solve your problem.
    • For all the other cases, follow me.

    The problem here is the following: you cannot map a drive to a network location and expect a windows service to read from it - if you Google this issue you will find a lot of information about it and some kind of not officially supported workaround.
    A "clearer" solution actually is to map the drive from within the service; so if we need to reach the path from NAV, we will have to map the drive from C\AL code so that the NAV service will be able to reach it.

    You could use Powershell, or just issue a "net use" command from NAV to map the drive; be careful as after rebooting the service (or the server) you "may" need to map the drive again (in my experience peersistent is useless for this scenario).

    Bad (but working) Code Example:
      //Build File
      //Hardcoded command and drive, write better code for yourself
      locFile.WRITE('net use Z \\AZURESTORAGENAME /u:USERNAME ACCESSKEY /persistent:yes');
      locFileName:=COPYSTR(locFileName,1,STRLEN(locFileName)-4)+'.bat'; //Didn't want to change the setting on the service
      //Run It
      SLEEP(3000); //Empirical
      IF ERASE(locFileName) THEN;
    //Do whatever pleases you with your Z drive

  • jordi79jordi79 Member Posts: 192
    In your code there is -->

    GabMem wrote: »
      //Run It


    What variable type is Process?


Sign In or Register to comment.