Forum Discussion
Copilot Studio Agent Unable to Retrieve Usable DOCX/XLSX Content from OneDrive (and SharePoint)
This is a platform limitation, not a file problem. When OneDrive or SharePoint Get file content is added directly as an agent tool, Copilot Studio turns the binary output into a text string. Bytes that aren't valid text get replaced with the ? character, so the DOCX/PDF is permanently corrupted. The poster's own tests in the thread confirm this: txt and md files came back fine, docx and pdf didn't, with both connectors. No admin setting fixes it. The "enable a binary-preserving download path" message one person got is just the model guessing, not a real switch.
The fix is to stop exposing Get file content directly as a tool. Which option to use depends on what the agent actually needs.
Option 1: The agent needs to understand what's in the file (most common)
This needs no binary handling at all:
- Add the OneDrive/SharePoint folder as a Knowledge source. Copilot Studio indexes docx, xlsx and pdf text itself, and the agent can answer questions from it directly.
- For Excel data: use Excel Online (Business) → List rows present in a table inside an agent flow, and return the rows as JSON. The data has to be formatted as an Excel table.
Option 2: The agent needs the actual file (e.g. code interpreter with python-docx/openpyxl)
Wrap the download in an agent flow so the file comes back as base64 text, which survives the conversion:
- Copilot Studio → Tools → Add a tool → New agent flow.
- Trigger: When an agent calls the flow, with an input such as FilePath (or file ID).
- Action: OneDrive for Business → Get file content using path (or SharePoint → Get file content).
- Respond to the agent with a Text output FileBase64 set to this expression:
body('Get_file_content_using_path')?['$content']
For binary files this property is already base64. If it comes back empty, use base64(body('Get_file_content_using_path')) instead.
5. Add a second output FileName so the code knows the extension.
6. In the agent instructions, add something like: "The file tool returns base64. Decode it with base64.b64decode() and save it as a file before opening it with python-docx/openpyxl."
Caveat for Option 2: base64 is about 33% bigger than the original file, and it all goes into the model's context. A 14 KB docx is fine; files of several MB will hit tool-response or token limits. For larger files, do the extraction inside the flow (Option 1 style) rather than passing the whole file to the agent.
Quick fix to try first
Open the existing Get file content tool → Inputs → set Infer Content Type = No. Sometimes this changes the response shape, but it doesn't reliably stop the text conversion. Treat Option 2 as the real fix.