How to Add File Size Column to SharePoint Online Document Library?
Requirement: Add file size column to SharePoint Online.
How to Show File Size in SharePoint Online?
Are you looking to add a column to your SharePoint Online document library that displays the size of each file? Well, You can add the “File Size” column to any list view of the SharePoint Online document library to get the size of each file. Just follow these steps to add the file size column to SharePoint Online:
- Navigate to the SharePoint Online Document Library.
- Click on the “Views” drop-down in the top-right corner area >> Click on “Edit Current View”.
- Search for the “File Size” field under “Columns”, include it in the view, and set the order in which you want it to appear in your view.
- Click on “OK” to save the changes to your view.
This adds the “File Size” column to the view and shows the size of each document in the view:
Please note, this is the size of the file without version history!
PnP PowerShell to Add File Size Column to the Default View
Adding a file size column to a SharePoint Online document library can be accomplished using PowerShell as well. Before you begin, you will need to have the PnP PowerShell module installed on your computer and be connected to your SharePoint Online site using the Connect-PnPOnline cmdlet.
Here is the PnP PowerShell to include the “File Size” field in the default view of a SharePoint Online document library (If it’s not already added!).
# Parameter
$SiteURL = "https://crescent.sharepoint.com/sites/Retail"
$ListName = "Documents"
$ColumnName = "FileSizeDisplay" #InternalName
Try {
# Connect to PnP Online
Connect-PnPOnline –Url $SiteURL -Interactive
#Get the List Default View
$List = Get-PnPList -Identity $ListName -Includes DefaultView
#Get the List View from the list
$ListView = Get-PnPView -List $ListName -Identity $List.DefaultView.Title
#Check if view doesn't have the column already
If($ListView.ViewFields -notcontains $ColumnName)
{
#Add Column to View
$ListView.ViewFields.Add($ColumnName)
$ListView.Update()
Invoke-PnPQuery
Write-host -f Green "Column '$ColumnName' Added to View!"
}
else
{
Write-host -f Yellow "Column '$ColumnName' Already Exists in View!"
}
}
catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
My other post on getting the size of a file using PowerShell: How to Get File Size using PowerShell in SharePoint Online?
How can I change the File Size column from items to bytes?
How we add file size column to view using rest api which gives size in KB not in Byte
Can u copy this information of Filesize into any other column in the same library?