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:

  1. Navigate to the SharePoint Online Document Library.
  2. Click on the “Views” drop-down in the top-right corner area >> Click on “Edit Current View”.
  3. 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.
  4. 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:

how to add file size column in sharepoint online

Please note, this is the size of the file without version history!

You can also get the size of each file from the properties of the file in Explorer view or from SharePoint Designer!

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?

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

3 thoughts on “How to Add File Size Column to SharePoint Online Document Library?

  • How can I change the File Size column from items to bytes?

    Reply
  • How we add file size column to view using rest api which gives size in KB not in Byte

    Reply
  • Can u copy this information of Filesize into any other column in the same library?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *