Importing/Exporting Word document from NAV Blob sometimes results in corrupted file

PConijn
Member Posts: 31
NAV2015 - Build 40459
We have a functionality where users can create word documents for a record. This is stored in a Blob field; nothing special so far.
Here's where it gets interesting:
If I save my document (before importing it) via NAVWordHelper.CallSaveAs:
However:
If I save my document (before importing it) via NAVWordHelper.CallSaveAsFormat with wdFormatStrictOpenXMLDocument format:
Windows regional settings have no impact on either set of results.
Other information:
Edit: updated for testing of additional languages
We have a functionality where users can create word documents for a record. This is stored in a Blob field; nothing special so far.
Here's where it gets interesting:
If I save my document (before importing it) via NAVWordHelper.CallSaveAs:
- If my Word application default language is Dutch (even with English also present) it will work fine;
- If my Word application default language is English (with or without Dutch present), it produces a "Document appears to be corrupted" error
However:
If I save my document (before importing it) via NAVWordHelper.CallSaveAsFormat with wdFormatStrictOpenXMLDocument format:
- If my Word application default language is English (with or without Dutch present) it will work fine;
- If my Word application default language is Dutch (even with English also present), it produces a "Document appears to be corrupted" error
Windows regional settings have no impact on either set of results.
Other information:
- I have not yet tested with other languages, but I would have thought that OpenXmlFormat would be language independent.
- It seems that only Dutch (Netherlands) is causing an issue with the wdFormatStrictOpenXMLDocument - I have tested Arabic (Iraq), Chinese (PRC), Dutch (Belgium) and German and they all seem to work well
- Blob compression settings have no impact.
- The corruption seems to be present in the Styles.xml at least
- The corruption might be linked to collation, since in the corrupted file (Styles.xml) "Colorful" is consistently represented as Col5rful (as in w:name="Col5rful List Accent 4")
- Using TextEncoding other than Windows while importing/exporting the blobs produces I/O errors - most likely because TextMode = FALSE.
- Using TextEncoding in the CreateOutStream/CreateInStream functions likewise has no effect
- Environment is NAV2015 - Build 40459
- I have tried several other methods of storage, but none have proved multilingually sound, so far
Edit: updated for testing of additional languages
0
Best Answer
-
Thank you, Jan.
I think I may have found the cause (or, in any case, a solution). It seems that the problem is caused by importing using NAV instreams to read the file. I have used a .NET filestream to import and export and that seems to have done it.ImportClientFileToBlob(VAR ptmprecTempBlob : Record TempBlob;ptxtFilename : Text) IF NOT EXISTS(ptxtFilename) THEN EXIT; ltxtServerTempFile := cduFileMgt.UploadFileSilent(ptxtFilename); IF NOT EXISTS(ltxtServerTempFile) THEN EXIT; netFileStream := netFileStream.FileStream(ltxtServerTempFile, lnetFileMode.Open, lnetFileAccess.Read); netArray := netArray.CreateInstance(lnetType.GetType('System.Byte'), netConvert.ToInt32(netFileStream.Length)); netFileStream.Read(netArray, 0, netConvert.ToInt32(netArray.Length)); ptmprecTempBlob.Blob.CREATEOUTSTREAM(osWriter); COPYSTREAM(osWriter, netFileStream); netFileStream.Close; cduFileMgt.DeleteServerFile(ltxtServerTempFile);
I hope this solves your issue as well!5
Answers
-
I have produced the same error using the 'Custom Report Layouts' standard functionalityJan Veenendaal1
-
Thank you, Jan.
I think I may have found the cause (or, in any case, a solution). It seems that the problem is caused by importing using NAV instreams to read the file. I have used a .NET filestream to import and export and that seems to have done it.ImportClientFileToBlob(VAR ptmprecTempBlob : Record TempBlob;ptxtFilename : Text) IF NOT EXISTS(ptxtFilename) THEN EXIT; ltxtServerTempFile := cduFileMgt.UploadFileSilent(ptxtFilename); IF NOT EXISTS(ltxtServerTempFile) THEN EXIT; netFileStream := netFileStream.FileStream(ltxtServerTempFile, lnetFileMode.Open, lnetFileAccess.Read); netArray := netArray.CreateInstance(lnetType.GetType('System.Byte'), netConvert.ToInt32(netFileStream.Length)); netFileStream.Read(netArray, 0, netConvert.ToInt32(netArray.Length)); ptmprecTempBlob.Blob.CREATEOUTSTREAM(osWriter); COPYSTREAM(osWriter, netFileStream); netFileStream.Close; cduFileMgt.DeleteServerFile(ltxtServerTempFile);
I hope this solves your issue as well!5
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions