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, ...