Downloading a file from an URL in NAV 2009 R2

navision2009R2
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.
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.
0
Best 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 Client@1000000000 : Boolean; PROCEDURE DownLoadFile@1000000012(URL@1000000000 : Text[1024];FileName@1000000008 : Text[1024]); VAR XmlHttp@1000000003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A0B-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.ServerXMLHTTP60"; InStr@1000000001 : InStream; OutStr@1000000007 : OutStream; CompInf@1000000002 : 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
1
Answers
-
hi ,
Can you use automation variable with create(automation,true,true.
Hope this can help you-1 -
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 Client@1000000000 : Boolean; PROCEDURE DownLoadFile@1000000012(URL@1000000000 : Text[1024];FileName@1000000008 : Text[1024]); VAR XmlHttp@1000000003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A0B-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.ServerXMLHTTP60"; InStr@1000000001 : InStream; OutStr@1000000007 : OutStream; CompInf@1000000002 : 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
1
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions