'ClosedXML Gives 'File Corrupt' Error, But File is Not Corrupt (VB.net)

I am using the ClosedXML package (version 0.95.4) to open an Excel file (.xlsx), which was previously saved in a folder to which the application has access. This is proven by the fact that the application can save to this folder.

However, when I attempt to open the file using ClosedXML, I receive an error that the file is corrupt.

System.IO.FileFormatException: 'File contains corrupted data.'

When I open the file directly using Excel, the file opens normally, with no errors. I should also add that this code was working perfectly before, and suddenly stopped working.

This is the code where the file is saved.

' Save the file to standard temp folder
Dim dirDownloads As String = System.IO.Path.GetTempPath
Randomize()
Dim strFileCode As String = (CInt(Int(Rnd() * 99999999)) + 10000000).ToString & "_" & fn
Dim fp As String = dirDownloads & "\" & strFileCode
fp = Replace(fp, "\\", "\")

fup_ESPM.SaveAs(fp)

For clarity, fup_ESPM is a FileUpload control.

And this is the code where ClosedXML attempts to open the file.

Sub SQL_Upload_ESPM_Template_Data(FilePath As String)
    ' Open target file
    Dim cxlDoc As XLWorkbook = New XLWorkbook(FilePath) ' This is the line where the error is occuring


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source