Download File From NAV Client, into SERVER.

BlackD1ece
Member Posts: 1
Hello m8ts, So this is my first post and I hope I'm not duplicating it. I've tried countless times to look internet for a solution (None was fully compatible whatsoever).
I have to create a tool wich first thing it needs to do is download a GZ file from an URL, but I'm not able to find the solution in any place.
I've found 2 so far:
1 - Using ADOStream:
URLINDEX := 'SOME URL';
IF(ISCLEAR(MXH)) THEN
CREATE(MXH,FALSE,TRUE);
MXH.open('GET',URLINDEX,FALSE);
MXH.send('');
IF MXH.status <> 200 THEN BEGIN
MESSAGE('ERROR');//TEST MESSAGE
CurrReport.BREAK;
END;
FileName := MXH.getResponseHeader('Content-Disposition');
IF STRPOS(FileName,'filename=') = 0 THEN
FileName :=''
ELSE BEGIN
FileName := COPYSTR(FileName,STRPOS(FileName,'filename=') + 10);
IF ISCLEAR(ADOStream) THEN
CREATE(ADOStream,FALSE,TRUE);
ADOStream.Type := 1;
ADOStream.Open;
ADOStream.Write(MXH.responseBody);
// ---> This line is commented from the online code found, because It wouldn't pass through here It would always close the stream. The url inputted is correct, and returns a download file if opened on a Browser.
//IF ADOStream.State = 1 THEN
//ADOStream.Close;
FileName := FICHEROS + FileName;
MESSAGE(FILENAME);
//CODE BREAKS HERE, IN SAVE FILE
ADOStream.SaveToFile(FileName,2);
//CURREPORT.BREAK;
ADOStream.Close;
END;
EDIT: Variables:
MXH Automation 'Microsoft XML, v6.0'.XMLHTTP60
ADOSTREAM Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Stream
FILESYSTEM Automation 'Windows Script Host Object Model'.FileSystemObject
FILENAME Text
FILEPATH Text
This will only execute "Error when writing to the file.". And as told URL and Locations are fine.
2 - Using InStream / OutStream.
URLINDEX := 'some url';
IF(ISCLEAR(MXH)) THEN
CREATE(MXH,FALSE,TRUE);
MXH.open('GET',URLINDEX,FALSE);
MXH.send();
IF MXH.status <> 200 THEN
MESSAGE('ERROR URL'); //MESSAGE FOR TESTING
FICHERO.CREATE(FICHEROS+'index_0.gz');
FICHERO.CREATEOUTSTREAM(ONS);
INS := MXH.responseStream;
COPYSTREAM(ONS,INS);
FICHERO.CLOSE;
EDIT:Variables
FICHERO File
MXH Automation 'Microsoft XML, v6.0'.XMLHTTP60
INS InStream
ONS OutStream
This won't work, he's not able to transform Automation on InStream.
Those codes, are from the internet modified (not mine) to get to do what I need.
Working under NAV 2016. Also tried a CodeUnit from a WebPage wich is suposed to download files (http://www.dynamics.is/?attachment_id=584), also unusable for our systems.
This thing is driving me so crazy I might end with 4 JaggerMeister bottles under a bridge hallucinating with nav streams.
Thank you very much,
I have to create a tool wich first thing it needs to do is download a GZ file from an URL, but I'm not able to find the solution in any place.
I've found 2 so far:
1 - Using ADOStream:
URLINDEX := 'SOME URL';
IF(ISCLEAR(MXH)) THEN
CREATE(MXH,FALSE,TRUE);
MXH.open('GET',URLINDEX,FALSE);
MXH.send('');
IF MXH.status <> 200 THEN BEGIN
MESSAGE('ERROR');//TEST MESSAGE
CurrReport.BREAK;
END;
FileName := MXH.getResponseHeader('Content-Disposition');
IF STRPOS(FileName,'filename=') = 0 THEN
FileName :=''
ELSE BEGIN
FileName := COPYSTR(FileName,STRPOS(FileName,'filename=') + 10);
IF ISCLEAR(ADOStream) THEN
CREATE(ADOStream,FALSE,TRUE);
ADOStream.Type := 1;
ADOStream.Open;
ADOStream.Write(MXH.responseBody);
// ---> This line is commented from the online code found, because It wouldn't pass through here It would always close the stream. The url inputted is correct, and returns a download file if opened on a Browser.
//IF ADOStream.State = 1 THEN
//ADOStream.Close;
FileName := FICHEROS + FileName;
MESSAGE(FILENAME);
//CODE BREAKS HERE, IN SAVE FILE
ADOStream.SaveToFile(FileName,2);
//CURREPORT.BREAK;
ADOStream.Close;
END;
EDIT: Variables:
MXH Automation 'Microsoft XML, v6.0'.XMLHTTP60
ADOSTREAM Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Stream
FILESYSTEM Automation 'Windows Script Host Object Model'.FileSystemObject
FILENAME Text
FILEPATH Text
This will only execute "Error when writing to the file.". And as told URL and Locations are fine.
2 - Using InStream / OutStream.
URLINDEX := 'some url';
IF(ISCLEAR(MXH)) THEN
CREATE(MXH,FALSE,TRUE);
MXH.open('GET',URLINDEX,FALSE);
MXH.send();
IF MXH.status <> 200 THEN
MESSAGE('ERROR URL'); //MESSAGE FOR TESTING
FICHERO.CREATE(FICHEROS+'index_0.gz');
FICHERO.CREATEOUTSTREAM(ONS);
INS := MXH.responseStream;
COPYSTREAM(ONS,INS);
FICHERO.CLOSE;
EDIT:Variables
FICHERO File
MXH Automation 'Microsoft XML, v6.0'.XMLHTTP60
INS InStream
ONS OutStream
This won't work, he's not able to transform Automation on InStream.
Those codes, are from the internet modified (not mine) to get to do what I need.
Working under NAV 2016. Also tried a CodeUnit from a WebPage wich is suposed to download files (http://www.dynamics.is/?attachment_id=584), also unusable for our systems.
This thing is driving me so crazy I might end with 4 JaggerMeister bottles under a bridge hallucinating with nav streams.
Thank you very much,
0
Answers
-
What version of NAV are you running on?0
-
[Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Did you experience File Management Codeunit. I believe you need to go through once it will do your Job.Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
Hi!
Did you get any solution? I'm finding the same situation, I need to download a PDF file from an URL. This URL is a field of the "Item" table. Did you get the way to download an external file?
Thank you very much!0 -
Simplest method would be using WebClient.DownloadFile.1
-
Duikmeester wrote: »Simplest method would be using WebClient.DownloadFile.
Thanks for your quick answer.
As I've seen, you recommend me to use C# code. That wouldn't be any problem, but I don't know how to use it in my approach, may be I've not explain myself correctly. The thing is that, I need to download the PDFs from NAV2013. The idea is to download the PDFs to a temp folder, when I create a quote for one customer, and after, include them on an email, that is going to be sent to the customer.
is this possible?
Thank you!0 -
Duikmeester wrote: »Simplest method would be using WebClient.DownloadFile.As I've seen, you recommend me to use C# code.
Duikmeester recomended you a .NET class. You can use in in C/AL by declaring a variable of type DotNet and subtypeSystem.Net.WebClient.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Thanks @Duikmeester for this info.
1 -
Duikmeester wrote: »Simplest method would be using WebClient.DownloadFile.As I've seen, you recommend me to use C# code.
Duikmeester recomended you a .NET class. You can use in in C/AL by declaring a variable of type DotNet and subtypeSystem.Net.WebClient.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Thanks @Duikmeester for this info.
Thanks both of you for the help. I'm finding some problems to apply what you have said.
I have created a function in a CU we use for mending functions, like this:
The local variables:
WebClient DotNet System.Net.WebClient.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
URL Text 100
The subtype of the DotNet is, as you have said,System.Net.WebClient.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
When I run the codeUnit, I see the next error:The instance for the DotNet variable hasn't been created. It's trying to be called from System.Net.WebClient.DownloadFile in CodeUnit Mending Functions: DownloadPDFFronURL
What I'm doing wrong?
0 -
Hi,
Use the Constructor method to initialize the variable:WebClient := WebClient.WebClient;
Some classes in .NET are static and can be used without construction, but most need to be initialized.0 -
Hi,
Use the Constructor method to initialize the variable:WebClient := WebClient.WebClient;
Some classes in .NET are static and can be used without construction, but most need to be initialized.
Thank you!
I have initialize the WebCLient, and now i see the next error:Access denied to 'c:/windows/system32/1001.pdf'..
Really appreciate your help!0 -
Hi,
Use the Constructor method to initialize the variable:WebClient := WebClient.WebClient;
Some classes in .NET are static and can be used without construction, but most need to be initialized.
Thank you!
I have initialize the WebCLient, and now i see the next error:Access denied to 'c:/windows/system32/1001.pdf'..
Really appreciate your help!
Try
FilePath := 'C:\Users\UserName\Desktop\1010.pdf';
WebClient.DownloadFile(URL,FilePath);1 -
Hi,
Use the Constructor method to initialize the variable:WebClient := WebClient.WebClient;
Some classes in .NET are static and can be used without construction, but most need to be initialized.
Thank you!
I have initialize the WebCLient, and now i see the next error:Access denied to 'c:/windows/system32/1001.pdf'..
Really appreciate your help!
Try
FilePath := 'C:\Users\UserName\Desktop\1010.pdf';
WebClient.DownloadFile(URL,FilePath);
Really thanks, it worked!!!!0 -
Hi,
Use the Constructor method to initialize the variable:WebClient := WebClient.WebClient;
Some classes in .NET are static and can be used without construction, but most need to be initialized.
Thank you!
I have initialize the WebCLient, and now i see the next error:Access denied to 'c:/windows/system32/1001.pdf'..
Really appreciate your help!
Try
FilePath := 'C:\Users\UserName\Desktop\1010.pdf';
WebClient.DownloadFile(URL,FilePath);
Really thanks, it worked!!!!
Great0 -
Hi all experts, I am testing some file downloading from https URL, and found this post, but I could not find system.net.webclient from .net, only can find system.net. I am using NAV2017 build 16585. Am I missing anything?
Thanks0 -
WebClient is found in the assembly System.0
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