XMLport to import xml from file on website

jimmyfjimmyf Member Posts: 104
In Dynamics NAV 2013 I am trying run an XMLport from a codeunit that I will execute from a NAS.
The xmlport has been designed to import exchange rates. The source file is hosted on a web server however the problem I get when running the codeunit is that it errors saying it cant find the file. the message in the event viewer is .. The specified path is invalid.

My code is below. Can this actually be done via an xmlport by opening a file hosted on a webserver?

XMLFile.OPEN('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml');
XMLFile.CREATEINSTREAM(XMLInstreamStream);
XMLPORT.IMPORT(XMLPORT::"Import Exchange Rates",XMLInstreamStream);
XMLFile.CLOSE;

Answers

  • DuikmeesterDuikmeester Member Posts: 308
    edited 2016-02-22
    You will first have to download the file, as the NAV file/stream object cannot handle URL's.
    Use something like WebClient.DownloadFile('http....','c:\.....') and then open the local file.

    See: https://msdn.microsoft.com/en-us/library/ez801hhe
  • Wisa123Wisa123 Member Posts: 308
    Duikmeester is correct on this one.

    However you can always use System.XML to load the data straight from the web.
    But this also means you can't use a xmlport to import your data.

    Did this exact example a few years ago, wouldnt mind sharing if you want it.
    Austrian NAV/BC Dev
Sign In or Register to comment.