I have a Blob Object in NAV, which represents an Excel document. I want this document to be displayed in my JavaScript Control AddIn (run in Web- and Windows-Client). But I am not sure how to handle this problem. Later in the AddIn, I need the Blob as a binary string.
So far I tried two things.
First try
I build an interface with this method
[ApplicationVisible]
void SetExcelDocument(ExcelDocument ExcelDocument);
and the ExcelDocument
- Object looks like this
[Serializable]
public class ExcelDocument
{
//Constructor
public ExcelDocument()
{
CurrentExcelDocument = null;
}
//store Blob
public Stream CurrentExcelDocument { get; set; }
}
So in NAV, i convert the Blob in a .Net MemoryStream variable, which looks like this
MemStream DotNet System.IO.System.IO.MemoryStream.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
and the code like this
TechnicalSpreadsheet.CALCFIELDS(Document); //Get Blob (Document is table column name)
TechnicalSpreadsheet.Document.CREATEINSTREAM(Lstr_BlobInstream);
MemStream := MemStream.MemoryStream();
COPYSTREAM(MemStream,Lstr_BlobInstream);
ExcelDocument := ExcelDocument.ExcelDocument; //Initialize Object
ExcelDocument.CurrentExcelDocument := MemStream; //set MemoryStream
CurrPage.spreadsheet.SetExcelDocument(ExcelDocument); //Call function in AddIn
The code is executed, when the AddIn is ready. the Nav variable ExcelDocument
is defined as this
ExcelDocument DotNet <Reference to Object here>, Version=8.0.0.0, Culture=neutral, PublicKeyToken=d02dbb9bbac93844'
So the problem here is, I can only set an instance of ExcelDocument
in NAV, when the property "RunOnClient" is set to yes. But this is not working for the WebClient (Source). But however even setting the property to yes, won`t send the data to the AddIn.
Second Try
For the second try, I changed the datatype. So I used a byte[]
instead of a stream. So ich changed the interface to this
[ApplicationVisible]
void SetExcelDocument(byte[] ExcelDocument);
and just changed the AddIn function call in NAV to this
CurrPage.spreadsheet.SetExcelDocument(MemStream.ToArray); //Call function in AddIn
and removed the ExcelDocument
variable.
This works but the data does not look like binary data. I would expect some unreadable stuff when displaying it in the web console, but I get readable letters and numbers instead. And I am not sure how to convert this to a binary string.
There is some nice input from Vjeko, but this does not work for me either.
I found a solution to send the blob to JavaScript Control AddIn. Here is what i did.
In the interface of the control AddIn I defined the method
where the
ExcelDocument
- Object looks like thisThe magic is now happening in the new
Converter
- class. Shortly I convert the byte array to a Stream, then read the Stream (respectively the Excel document) with the help of EPPlus and finally convert the content of the document with Newtonsoft.JSON to a Json string (variableExcelJson
).In NAV it will look like this.
This works for me.
I have this piece of code to add binary node to XML file. By this I was able to send file as binary data to web service. Try play with it maybe it will help. It uses ActiveX because it was written for Nav 5. You can replace it with .net.