SharePointVault ~/gotchas/rest-api ⌕ Search 404 pages, error messages, scripts…Ctrl K ★ Star
M↓ README.mdM↓ file-size-needs-expand-file.md
sharepoint-vault›gotchas›rest-api›file-size-needs-expand-file.mdhistoryedit on GitHub
● GOTCHArest-api· 1 min read

File size in a document library: File_x0020_Size 400s — use $expand=File

applies to: SharePoint Onlinereviewed: 2026-07-15#rest-api#files#libraries

File_x0020_Size is a computed column that 400s in $select — read the size from the File relation instead via $expand=File and File/Length.

File_x0020_Size je počítaný sloupec, který v $select spadne na 400 – velikost čti z relace File přes $expand=File a File/Length.

Symptom

Listing documents with their size:

GET …/items?$select=Id,FileLeafRef,File_x0020_Size

fails with HTTP 400 — even though File_x0020_Size is a perfectly real column you can see in list settings, and the near-identical File_x0020_Type selects just fine.

Cause

File_x0020_Size is a computed column and computed columns can't be projected through $select on the items endpoint. The inconsistency with File_x0020_Type (which works) is what makes this one feel like a bug rather than a rule — it costs people an hour of staring at a correct-looking query.

Fix

Get file facts from the File relation instead:

GET …/items?$select=Id,FileLeafRef,File/Length,File/UIVersionLabel&$expand=File
  • size → File/Length (bytes, as a string — parse before math)
  • version → File/UIVersionLabel
  • name/extension → FileLeafRef (split on the last dot)

Notes

  • If a library query 400s and you recently added any field to $select, bisect the select list before blaming permissions — a computed or non-queryable column is the usual culprit. A defensive fallback to a minimal $select keeps the UI alive.
  • FieldValuesAsHtml won't rescue you here — file size isn't reliably in it either, and that endpoint has its own escaping quirks. $expand=File is the boring answer that works.
Was this helpful?ask or add your experience on GitHub →
Saved you an hour? A star on GitHub helps other SharePoint people find the vault.★ Star on GitHub
last reviewed: 2026-07-15last updated: 2026-09-24historyedit on GitHubview source