cancel
Showing results for 
Search instead for 
Did you mean: 

Utility.WriteStreamToFile() corrupting Excel workbook

Vince_Fedorchak
Champ in-the-making
Champ in-the-making

When using the thick client to export a stored Excel document to disk (via File - Save As), it opens fine in Excel 2013.

However, when using the Unity API (via Utility.WriteStreamToFile()), it is corrupting the Excel file (.xlsm). When opening the file in Excel after exporting via the Unity API, Excel prompts with the error "We found a problem with some content in <file>. Do you want us to try and recover as much as we can?"

Is there a known issue or possible workaround?

The call looks like this:

Utility.WriteStreamToFile(app.Core.Retrieval.Default.GetDocument(args.Document.DefaultRenditionOfLatestRevision).Stream, outputFilePath + ".xlsm");

1 ACCEPTED ANSWER

Tyler_Sorber
Star Collaborator
Star Collaborator

Hi Vince

There are two suggestions that I have that may help

1) Do not place you code contained within a Single line.  This will help spot memory leaks, and which service request the issue is occuring on.  In this case, the GetDocument Method will return a PageData Object that implements IDisposable.  Without Dispose being called, or being wrapped in a Using statement, this obect is leaked on the Server.

2) From the PageData Object, the Extension Property can be used to ensure that the file exported has the proper extension.  I would assume this issue is due to an improper extension being used.

For reference, before is what I would expect from your code block

Rendition rendition = document.DefaultRenditionOfLatestRevision;DefaultDataProvider defaultDataProvider = app.Core.Retrieval.Default; using (PageData pageData = defaultDataProvider.GetDocument(rendition)){    string fullPath = string.Format("{0}.{2}", outputFilePath, pageData.Extension);    Utility.WriteStreamToFile(pageData.Stream, fullPath);}

View answer in original post

1 REPLY 1

Tyler_Sorber
Star Collaborator
Star Collaborator

Hi Vince

There are two suggestions that I have that may help

1) Do not place you code contained within a Single line.  This will help spot memory leaks, and which service request the issue is occuring on.  In this case, the GetDocument Method will return a PageData Object that implements IDisposable.  Without Dispose being called, or being wrapped in a Using statement, this obect is leaked on the Server.

2) From the PageData Object, the Extension Property can be used to ensure that the file exported has the proper extension.  I would assume this issue is due to an improper extension being used.

For reference, before is what I would expect from your code block

Rendition rendition = document.DefaultRenditionOfLatestRevision;DefaultDataProvider defaultDataProvider = app.Core.Retrieval.Default; using (PageData pageData = defaultDataProvider.GetDocument(rendition)){    string fullPath = string.Format("{0}.{2}", outputFilePath, pageData.Extension);    Utility.WriteStreamToFile(pageData.Stream, fullPath);}
Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.