Post

#PowerPlatformTip 124: 'Recognize Plain Text File Formats'

#PowerPlatformTip 124: 'Recognize Plain Text File Formats'

TL;DR: “Get file content” (SharePoint, OneDrive for Business) infers the content type from the file extension. Text formats such as .txt, .csv, .xml or .html come back as plain text and .json as a JSON object, so body('Get_file_content') is usable directly. Binary files come back as an object with $content-type and a base64 $content. Strip a UTF-8 BOM before you parse CSV or JSON.

💡 Challenge

You read a file in a flow and want to work with its text: split a CSV, parse a JSON configuration, search a log. Sometimes the output is readable text, sometimes it is a $content blob in base64, and the same expression fails on the other kind.

✅ Solution

Know what decides the output: the Infer Content Type setting of “Get file content” (on by default) maps the file extension to a content type. Text types are returned as a string, everything else as a base64 object. Pick the expression that matches.

🔧 How It’s Done

1. Get the file

🔸 Add Get file content (SharePoint) or Get file content / Get file content using path (OneDrive for Business) and leave Infer Content Type set to Yes.

2. Text file: use the body directly

🔸 For .txt, .csv, .xml, .html and similar text formats the output is the text itself. A .json file comes back as a JSON object whose properties you can address directly:

1
body('Get_file_content')

🔸 Example CSV, one array element per line:

1
split(body('Get_file_content'), decodeUriComponent('%0A'))

3. Binary or unknown type: decode $content

🔸 If the run output shows {"$content-type": "...", "$content": "..."}, decode the base64:

1
base64ToString(body('Get_file_content')?['$content'])

🔸 This happens for extensions the service doesn’t map to a text type and when Infer Content Type is set to No.

4. Remove the BOM

🔸 Files saved as “UTF-8 with BOM” (Excel’s CSV UTF-8, many Windows editors) start with an invisible byte order mark. It ends up in the first column name or makes json() fail. Remove it first:

1
replace(string(body('Get_file_content')), decodeUriComponent('%EF%BB%BF'), '')

🔸 string() makes the expression work even when the body of a .json file is already handed over as JSON. Wrap the result in json() to get an object again.

🔸 Files in a legacy encoding such as Windows-1252 show umlauts and accents as �. Save them as UTF-8 at the source.

🎉 Result

Text files are processed directly, without a decoding step, and binary files are decoded only when needed. CSV headers and JSON parse cleanly because the BOM is gone.

🌟 Key Advantages

🔸 Simpler flows: no decoding action for text formats.

🔸 Predictable: the extension tells you which expression to use.

🔸 Robust parsing: removing the BOM prevents the classic “first column not found” error.

🎥 Video Tutorial

🛠️ FAQ

1. Which file formats come back as plain text?

Extensions that map to a text content type, for example .txt, .csv, .xml and .html. A .json file comes back as a JSON object. Check the run output once: readable text means plain text, a $content object means base64.

2. Do all connectors behave the same way?

The SharePoint and OneDrive for Business “Get file content” actions infer the type from the extension. Other connectors can return binary content regardless of the extension, so check the run output.

3. How do I handle formats that output as base64?

Use base64ToString(body('Get_file_content')?['$content']) for text content. For real binary files (PDF, images, ZIP), pass body('Get_file_content') unchanged to the next action, for example “Create file”.

This tip is by Marcel Lehmann, Microsoft MVP (Business Applications) and founder of the Power Platform Academy – live Power Platform workshops, free or CHF 49. Join the workshop waitlist to get notified about new dates. For companies that want this implemented for them, see KMUpower – Power Platform consulting & automation for SMEs (DACH).

This post is licensed under CC BY 4.0 by the author.

Microsoft and the Power Platform product names (for example Power Apps, Power Automate, Copilot Studio) are trademarks of the Microsoft group of companies. This is an independent website. It is not operated, sponsored or endorsed by Microsoft.