Base64 - ADOStream.writetext error

livingdoll
Member Posts: 45
Hi there,
I am using Base64 encoding (based on an example found here on Mibuso, using the 'CG Request Client' Base64 function) to encrypt a xml file to base64. The base64 encoded file is then incorporated in another xml structure and then sent to a webservice. Running from a classic client, everything goes well. From the RTC, exporting a country/region code or a currency code is no problem either. The encoded file is created beautifully. But when I try to export a bigger entity (for example a purchase order) from the RTC, I recieve the following error:
Unable to convert from Microsoft.Dynamics.Nav.Runtime.NavBigText to System.String
The problem is caused in the ADOStream.WriteText( DomNode.nodeTypedValue) statement in the following code:
The Base64 function converts a physical file to a Base64 encoded string, stored in a DomNode. The ADOStream is then used to write this DomNode to another physical file. It does its job fine for small input files, but bigger ones make it crash with the error message as stated above. It seems ADOStream.Writetext does not like the big encoded file?
Does anyone know of another technique to write the DomNode.nodeTypedValue to a physical file? I have physical file as input and I want a physical base64-encoded version of that file (with another extension).
Best regards,
Josh
I am using Base64 encoding (based on an example found here on Mibuso, using the 'CG Request Client' Base64 function) to encrypt a xml file to base64. The base64 encoded file is then incorporated in another xml structure and then sent to a webservice. Running from a classic client, everything goes well. From the RTC, exporting a country/region code or a currency code is no problem either. The encoded file is created beautifully. But when I try to export a bigger entity (for example a purchase order) from the RTC, I recieve the following error:
Unable to convert from Microsoft.Dynamics.Nav.Runtime.NavBigText to System.String
The problem is caused in the ADOStream.WriteText( DomNode.nodeTypedValue) statement in the following code:
CGBase64 Automation 'CG Request Client'.Base64
DomNode Automation 'Microsoft XML, v3.0'.IXMLDOMNode
DomDoc Automation 'Microsoft XML, v3.0'.DOMDocument
ADOStream Automation 'Microsoft ActiveX Data Objects 2.7 Library'.Stream
CREATE(CGBase64); CREATE(DomDoc); CREATE(ADOStream); DomNode := DomDoc.createElement('b64'); // just a dummy to do the conversion CGBase64.Encode( InFileName, DomNode); ADOStream.Type := 2; // text ADOStream.Charset := 'us-ascii'; ADOStream.Open; ADOStream.WriteText( DomNode.nodeTypedValue); IF EXISTS(TEMPORARYPATH+'\b64encoded.txt') THEN ERASE(TEMPORARYPATH+'\b64encoded.txt'); ADOStream.SaveToFile(TEMPORARYPATH+'\b64encoded.txt'); ADOStream.Flush; ADOStream.Close; CLEAR( ADOStream); CLEAR( DomNode); CLEAR( DomDoc); CLEAR( CGBase64);
The Base64 function converts a physical file to a Base64 encoded string, stored in a DomNode. The ADOStream is then used to write this DomNode to another physical file. It does its job fine for small input files, but bigger ones make it crash with the error message as stated above. It seems ADOStream.Writetext does not like the big encoded file?
Does anyone know of another technique to write the DomNode.nodeTypedValue to a physical file? I have physical file as input and I want a physical base64-encoded version of that file (with another extension).
Best regards,
Josh
0
Answers
-
-
Excellent solution!!!! Working like charm now. You made my day :-)
Best regards,
Josh0 -
Hi deV.ch / livingdoll,
the link no more exist. Do you have that code in other site?
Could you share it with me?
Thank in advance
----
deV.ch: I found some like it in your blog. Thank0 -
Base64
Here is an example.
http://www.kauffmann.nl/blog/index.php/ ... b-service/
and another example
http://blogs.msdn.com/b/freddyk/archive ... vices.aspx0
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