File.Contents

Accessing Data

Returns the contents of a file as binary.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

File.Contents(path as text) as binary

Parameters

NameTypeRequiredDescription
pathtextYesThe full file path to read.

Return Value

binaryThe binary content of the file.

Remarks

File.Contents reads a file from the local file system (or a network share) and returns its contents as a binary value. On its own, binary is not useful — you pipe it into a parser function to interpret the data:

| File type | Parser function | |---|---| | CSV / TSV | Csv.Document(File.Contents("..."), [Delimiter = ","]) | | Excel | Excel.Workbook(File.Contents("..."), true) | | JSON | Json.Document(File.Contents("...")) | | XML | Xml.Document(File.Contents("...")) | | Plain text | Lines.FromBinary(File.Contents("...")) |

### Important notes

- File.Contents is available in Power BI Desktop and Excel Desktop only. It is not supported in the Power BI Service, Excel Online, or Dataflows because these cloud environments do not have access to local file paths. - For cloud-based scenarios, use a gateway or switch to Web.Contents, SharePoint.Contents, or another cloud-compatible data source. - The path must be a fully qualified path (e.g., "C:\Data\sales.csv" or "\\server\share\file.xlsx").

### Typical pattern

``powerquery let Source = File.Contents("C:\Reports\quarterly.csv"), Parsed = Csv.Document(Source, [Delimiter = ",", Encoding = TextEncoding.Utf8]), Promoted = Table.PromoteHeaders(Parsed, [PromoteAllScalars = true]) in Promoted ``

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks