Corrupted file after saving BLOB !?

Hi, What I am trying is to save a Word doc into a blob field and extract back to a file to read using Word. The file resulted is corrupted: // - Save a Word Document in a Blob File // Update the BLOB Field (Document) in the Table FI.OPEN(strPath); // My Word Doc File FI.CREATEINSTREAM(NVInStream); Document.CREATEOUTSTREAM(NVOutStream); WHILE NOT (NVInStream.EOS()) DO BEGIN Written := NVInStream.READ(readVar,250); NVOutStream.WRITE(readVar,250); END; // I am extracting the Blob file back to the harddisk // (Word Doc) saved previous CALCFIELDS(Document); FO.CREATE(‘C:\MyDoc.Doc’); FO.CREATEOUTSTREAM(NVOutStream); Rec.Document.CREATEINSTREAM(NVInStream); WHILE NOT (NVInStream.EOS()) DO BEGIN Written := NVInStream.READ(readVar,250); NVOutStream.WRITE(readVar,250); END; FO.CLOSE(); // The file resulted is corrupted - word faills to open and the new size of the file created is greather then the original // Something I am doing wrong but I don’t know what. Thanks, Marcel

Hi Marcel, looks to me as if you’re writing too much data out as you’re always writing in blocks of 250 byte. You should take care that you only write as many bytes as are read on the last loop. Note though that I’m not familiar with stuff > financials 2.6 and am looking at this specific thing with the eyes of a c++ programmer :wink: bis bald, hlob

Greetings! Just use the CopyStream() function instead of trying to read/write using a variable. It will produce much better results. fyi: Binary Information cannot be read/written as text. You will need to read/write using a binary or character variable because of possible conversions to UniCode (ick) when using a text variable.

Hello, I have read the question numerous times and I don’t understand one thing: Is there anything that keeps you from using the BLOB.IMPORT and BLOB.EXPORT functions? To me, it seems the process of reading/writing the Word file with a FILE variable is changing the binary contents. It’s the same as taking Windows CALC.EXE, opening it in Notepad, saving it and then trying to run it again… it’s just not the same binary code. Or am I missing something?