System.IO.FileFormatException: File contains corrupted data

Category: open xml format sdk


jane.m on Wed, 27 Jun 2018 20:06:53


I use OpenXml library to count the number of pages in the pptx files uploaded by user. 90% of times it success but 10% of time it fails and give the error in the title.

The function I call is:

PresentationDocument.Open(file.InputStream, false), where the parameter "file" in this function is a Telerik class, Telerik.Web.UI.UploadedFile.

The stack trace is: 

System.IO.FileFormatException: File contains corrupted data.

   at MS.Internal.IO.Zip.ZipIOEndOfCentralDirectoryBlock.ValidateZip64TriggerValues()

   at MS.Internal.IO.Zip.ZipIOBlockManager.CreateLoadZip64Blocks()

   at MS.Internal.IO.Zip.ZipIOBlockManager.get_Zip64EndOfCentralDirectoryBlock()

   at MS.Internal.IO.Zip.ZipIOBlockManager.get_CentralDirectoryBlock()

   at MS.Internal.IO.Zip.ZipArchive.GetFiles()

   at System.IO.Packaging.ZipPackage.ContentTypeHelper..ctor(ZipArchive zipArchive, IgnoredItemHelper ignoredItemHelper)

   at System.IO.Packaging.ZipPackage..ctor(Stream s, FileMode mode, FileAccess access, Boolean streaming)

   at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode, FileAccess packageAccess, Boolean streaming)

   at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.OpenCore(Stream stream, Boolean readWriteMode)

   at DocumentFormat.OpenXml.Packaging.PresentationDocument.Open(Stream stream, Boolean isEditable, OpenSettings openSettings)

Another detail to provide is that when the code run locally it success 100% of the time, but when run on the server it gives this error. 

Any help is appreciated!


Terry Xu - MSFT on Thu, 28 Jun 2018 06:10:00

Hello jane.m,

Will it be related to specific document? What's the result if you open the document directly?

What's the result if you open the document from a  System.IO.Stream instead of the Telerik.Web.UI.UploadedFile.InputStream?

Best Regards,