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.