OpenBI Docs Buy

File.Contents

A file on this computer or a share, as a binary for a reader such as Csv.Document or Excel.Workbook.

Group: Files and documents. Power Query M has it too: a query that uses it is written as in Power BI.

Syntax

File.Contents(path as text, optional options as nullable record) as binary
ParameterTypeDescription
pathtextThe file's full path, such as C:\Data\sales.csv or a share's \\server\folder\file.
optionsnullable record
optional
Accepted as Power Query writes it; none is read.

Returns

binary. The file's bytes, read when something uses them.

Remarks

  • Nothing is read when File.Contents runs: the file is opened when a step reads its bytes. A file that isn't there is an error at that step.
  • Get data writes a file in the project's folder as ${PROJECT_DIR}/..., so the query still works when the project moves; a file elsewhere keeps its full path.
  • On OpenBI Server, a model reads only the folders its administrator lets it read.

Examples

How many bytes a file has

Binary.Length(File.Contents("C:\Data\people.json"))
117

A text file's lines

Lines.FromBinary(File.Contents("C:\Data\sales.csv"))
{"Product,Region,Sales,Note", "Chair,North,100,""""", "Desk,South,250,""big, heavy""", "Chair,South,75,""say """"hi""""""", "Lamp,North"}

Each line as it is in the file, its quotes and commas included.

Read by a reader

Json.Document(File.Contents("C:\Data\people.json"))[count]
2

Csv.Document, Excel.Workbook, Json.Document, Parquet.Document, Folder.Files, Binary.Length.

Last updated · OpenBI Studio 0.3.79