Skip to main content

File Attachment using Memory stream in D365 F&O AX 2012

In Dynamics Ax we normally came across file attachment of file. In my example I am attaching File that has been received in Memory stream. 


public void attachFile(str _file, PurchLine _purchline, CMTTankId _tankId, System.IO.MemoryStream _streamFile, DocuTypeId _DocType)
    {
        str                 pdfFile;
        DocuRef             docuref;
        System.Exception    ex;

        pdfFile     = _file+fileExt;
        try
        {
            _streamFile.Seek(0, System.IO.SeekOrigin::Begin);
            docuref = DocumentManagement::attachFileToCommon(_PurchLine,_DocType,_streamFile,                                       pdfFile, pdf,pdfFile);
        }
        catch (Exception::CLRError)
        {
            ex = ClrInterop::getLastException();
            if (ex != null)
            {
                ex = ex.get_InnerException();
                if (ex != null)
                {
                    error(ex.ToString());
                }
            }
        }
        catch (Exception::Error)
        {
            throw Exception::Error;
            
        }
    }
Note : Here is the Screenshot of the above code 

Comments