local procedure ReadAttachments(var InS: InStream; DocumentRef: RecordRef; iTableNo: Integer; txtNoFieldName: Text): BooleanvarrecDA: Record "Document Attachment";fldRef: FieldRef;iNoFieldNo: Integer;txtNoValue: Text;OutS: OutStream;TempBlobAtt: Codeunit "Temp Blob";Buffer: array[1024] of Byte;ReadBytes: Integer;bReturnValue: Boolean;beginbReturnValue := false;Clear(InS);// initialise OutSTempBlobAtt.CreateOutStream(OutS, TextEncoding::Windows);iNoFieldNo := GetFieldNumber(txtNoFieldName, iTableNo);recDA.SetFilter("Table ID", Format(iTableNo));fldRef := DocumentRef.Field(iNoFieldNo);txtNoValue := fldRef.Value;recDA.SetFilter("No.", txtNoValue);if recDA.FindSet() then beginbReturnValue := true;repeat// Create OutStream from "Document Attachment" object.// In other words, export the bytes of the "Document Attachment" database field into the OutStream.recDA."Document Reference ID".ExportStream(OutS);// Tie InS (InStream) to OutS (OutStream) via TempBlob objectTempBlobAtt.CreateInStream(InS, TextEncoding::Windows);// *** This line is erroring ***OutS.Write(InS);// *****************************until recDA.Next() = 0;// Now OutS contains data from all attachments// Create InStream from the same TempBlob// Clear(InS);TempBlobAtt.CreateInStream(Ins);// Now Ins contains the concatenated dataend;end;
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,902 Super User 2024 Season 2
Martin Dráb 229,336 Most Valuable Professional
nmaenpaa 101,156