Options

Base64 - ADOStream.writetext error

livingdolllivingdoll Member Posts: 45
edited 2013-11-06 in NAV Three Tier
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:
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

Answers

Sign In or Register to comment.