get attachment as base64
Tue Jan 23 2024 08:34:39 GMT+0000 (Coordinated Universal Time)
Saved by
@MinaTimo
public class NW_ContractRenewalServiceEntity extends common
{
/// <summary>
///
/// </summary>
public void postLoad()
{
DocuRef DocuRef;
DocuValue DocuValue;
NW_ContractRequest NW_ContractRequest;
super();
changecompany('SHC')
{
select DocuRef
where DocuRef.RefRecId == this.ContractRecId
&& DocuRef.RefTableId == tableNum(NW_ContractRenewalRequest);
//select DocuValue where DocuValue.RecId == DocuRef.ValueRecId;
if(DocuRef)
{
//DocuRef docuref;
//ITSGetFileFromDocMgmtInVariousFormats runnable = ITSGetFileFromDocMgmtInVariousFormats::construct();
//runnable.readfromDocuRefAttachments(docuref);
//BitMap fileContents = DocumentManagement::getAttachmentAsContainer(DocuRef);
//str fileBase64Str = con2base64str(fileContents);
BinData BinData;
using(System.IO.Stream fileStream = DocumentManagement::getAttachmentStream(DocuRef))
{
using(System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
fileStream.CopyTo(memoryStream);
this.Attach = System.Convert::ToBase64String(memoryStream.ToArray());
}
}
// or use this.Attach = DocuRef.getFileContentAsBase64String() insted of the above code from "ElectronicReporting" model
this.FileName = DocuRef.filename();
this.FileType = DocuRef.fileType();
}
}
}
}
content_copyCOPY
Comments