{FIX} Corrupt or Bad File When Trying to Open a File That Was Saved to SharePoint Using Power Automate

PROBLEM: The user creates a flow that saves files to a SharePoint document library, but the files cannot be opened.

This is a question that I am starting to see more often than I would like. The user creates a flow that saves files to a SharePoint document library, but the files cannot not be opened. What’s really strange is that the same actions work fine in other flows.

QUESTION
I have built a Flow that automatically uploads Excel email attachments to a SharePoint library. The Flow runs successfully, and appears to be okay, however I am unable to open the files from SharePoint (both web version and desktop version). Does anyone have any idea?

See: Forum Post #1: Uploading Excel email attachments to SharePoint library and Forum Post #2: Attachment excel to SharePoint malformed

Error message: Could not open the workbook (Excel file)

This Flow should work

The following flow saves email attachments to a SharePoint document library (step 4):

The following flow saves email attachments to a SharePoint document library

⚠️ But in some rare instances users have reported that saved files cannot be opened.

It seems as if the information about the file type (i.e. is the an image, Word document or Excel worksheet? etc) has been lost or the file is corrupt.
Example demonstrating the problem: The Excel file cannot be opened

It seems as if the information about the file type has been lost (i.e. Is the file an image, Word document or an Excel worksheet?) .

✅ The workaround for this issue

A workaround for this issue is to use a compose action to store the file content type and file content:

{
  "$content-type": <contentType>,
  "$content":  <contentBytes>
}

Then use the output of the compose action as the File Content in the SharePoint Create file action:

A work around to the issue is to use a compose action to store the file content type and file content. Then use the output of the Compose action for the File Content in the SharePoint Create file action:

❌ Testing by REMOVING the content-type information

If I remove the “$content-type” property from the Compose action I get the same error: “Couldn’t Open the Workbook”

If I remove the "$content-type" property from the Compose action
Error message: Could not open the workbook (Excel file)

It does seem that the information about file type has been lost (i.e. Is the file an image, Word document or an Excel worksheet?) . The examples I have so far seen affect Excel files, but it’s unclear if the issue affects other file types as well.

Notes

  1. Short Notes: The format of File Attachment Arrays for Approvals and Outlook Emails
  2. How to save email attachments to a SharePoint Document Library using Power Automate
  3. Forum Post #1: Uploading Excel email attachments to SharePoint library
  4. Forum Post #2: Attachment excel to SharePoint malformed

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Website Built with WordPress.com.

Up ↑

%d bloggers like this: