Downloading a file from an URL in NAV 2009 R2

navision2009R2navision2009R2 Member Posts: 8
I need to download a file, from an URL, in NAV 2009 R2.

I'm trying to do the following:
- request a list of files from a server using a XMLRequest => DONE
- list the files on a form so that users can select the desired one => DONE
- download the file from the same server into the users' TEMPORARYFOLDER => TODO.

How can I proceed ?

PS:
- I tried using a DotNet variable, but itt seems like on cannot use System.Net.HttpWebResponse in NAV 2009 R2
- I succed in opennig the file in iexplore using HYPERLINK(myUrl) so netwok config is OK
- Most of the time, files will be PDF ones, but it could also be so other file formats. You can assume I know the file format of the one need to download.
- The files are on an on-premise server, so you can assume downloading thoses files are safe.

Best Answer

  • ftorneroftornero MadridMember Posts: 485
    Answer ✓
    Hello @navision2009R2 ,

    You can use something like this:
    OBJECT Codeunit 50001 Download File from URL
    {
      OBJECT-PROPERTIES
      {
        Date=28/11/20;
        Time=23:02:06;
        Modified=Yes;
        Version List=DL FILE;
      }
      PROPERTIES
      {
        OnRun=BEGIN
              END;
    
      }
      CODE
      {
        VAR
          [email protected] : Boolean;
    
        PROCEDURE [email protected]([email protected] : Text[1024];[email protected] : Text[1024]);
        VAR
          [email protected] : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A0B-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.ServerXMLHTTP60";
          [email protected] : InStream;
          [email protected] : OutStream;
          [email protected] : TEMPORARY Record 79;
        BEGIN
          IF ISCLEAR(XmlHttp) THEN
            CREATE(XmlHttp, FALSE, NOT ISSERVICETIER);
    
          XmlHttp.open('GET', URL,0);
          XmlHttp.setTimeouts(10000,10000,10000,100000);
          XmlHttp.send('');
    
          IF XmlHttp.status = 200 THEN BEGIN
            InStr := XmlHttp.responseStream;
            CompInf.Picture.CREATEOUTSTREAM(OutStr);
            IF COPYSTREAM(OutStr, InStr) THEN
              CompInf.Picture.EXPORT(FileName);
          END;
    
          CLEAR(XmlHttp);
        END;
    
        BEGIN
        END.
      }
    }
    
    

    Regards

Answers

  • Etimos90Etimos90 Member Posts: 2
    hi ,
    Can you use automation variable with create(automation,true,true.


    Hope this can help you
  • ftorneroftornero MadridMember Posts: 485
    Answer ✓
    Hello @navision2009R2 ,

    You can use something like this:
    OBJECT Codeunit 50001 Download File from URL
    {
      OBJECT-PROPERTIES
      {
        Date=28/11/20;
        Time=23:02:06;
        Modified=Yes;
        Version List=DL FILE;
      }
      PROPERTIES
      {
        OnRun=BEGIN
              END;
    
      }
      CODE
      {
        VAR
          [email protected] : Boolean;
    
        PROCEDURE [email protected]([email protected] : Text[1024];[email protected] : Text[1024]);
        VAR
          [email protected] : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A0B-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.ServerXMLHTTP60";
          [email protected] : InStream;
          [email protected] : OutStream;
          [email protected] : TEMPORARY Record 79;
        BEGIN
          IF ISCLEAR(XmlHttp) THEN
            CREATE(XmlHttp, FALSE, NOT ISSERVICETIER);
    
          XmlHttp.open('GET', URL,0);
          XmlHttp.setTimeouts(10000,10000,10000,100000);
          XmlHttp.send('');
    
          IF XmlHttp.status = 200 THEN BEGIN
            InStr := XmlHttp.responseStream;
            CompInf.Picture.CREATEOUTSTREAM(OutStr);
            IF COPYSTREAM(OutStr, InStr) THEN
              CompInf.Picture.EXPORT(FileName);
          END;
    
          CLEAR(XmlHttp);
        END;
    
        BEGIN
        END.
      }
    }
    
    

    Regards
Sign In or Register to comment.