in a web application there is a document library and daily 1000 to 2000 documents are uploaded by users,

so here i want to calculate the average size of documents uploaded to this web application, so here i want to create a view based filesize column and apply filter on this column.

ex: filesize >500 KB

  • What condition you would want to have in your filter? Like you would want to show documents whose file size is greater than 500KB? – Asad Refai Aug 10 '15 at 7:44
  • i did not fount filesize column in filter condition while i creating a view..i taken the 500 kb is for example. i will check in some range values like 500 - 1000 kb and 1000 - 2000 – adilahmed Aug 10 '15 at 8:11
  • 1
    There is a column with internal name "FileSizeDisplay" try to create a view using that column programatically, or export any listview webpart and update the query – sekhar Aug 10 '15 at 9:23

You can create a view with File Size placed in the query using CSOM PowerShell. I have used the query mentioned by @Yayati. You can replace with yours.

this function need not compulsorily run on the SharePoint server. You can also run it from your remote machine provided you have Client Object Model namespaces on your remote machine.

function Create-ListView()

            #get Client Object
            $context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
            $context.Credentials = $credentials

            #Retrieve List
            $list = $context.Web.Lists.GetByTitle($listName)

            Write-Host "Error while getting context. Error -->> "  + $_.Exception.Message -ForegroundColor Red
            $viewQuery = '<Where><Lt><FieldRef Name='File_x0020_Size' /><Value Type='Number'>10000</Value></Lt></Where>' 
            $viewFields = New-Object System.Collections.Specialized.StringCollection  
            $ViewInfo = New-Object Microsoft.SharePoint.Client.ViewCreationInformation
            $ViewInfo.Query = $viewQuery
            $ViewInfo.RowLimit = 50
            $ViewInfo.ViewFields = $viewFields 
            $ViewInfo.Title = $viewName
            $ViewInfo.SetAsDefaultView = $false

            $view = $list.Views.Add($ViewInfo)
            Write-Host "View added successfully" -ForegroundColor Green

            Write-Host ("Error while creating view for a List. Error -->> " + $_.Exception.Message) -ForegroundColor Red



$credentials = Get-Credential
Create-ListView 'http://yoursite' $credentials 'Your Library Name' 'Name of your view'
| improve this answer | |

You are correct. The FileSize column is by default is not visible in filter section of View. So you can create a custom view using SharePoint Designer by using CAML Query.
Here are steps to create custom view:

  1. Go to Document Library settings -> Create View -> Custom View in SharePoint Designer
  2. Open the custom view in SharePoint Designer.
  3. Search for <View> tag and replace <Query/> tag with your CAML Query. e.g. here is the query to show file having filesize < 10kb

    <Query><Where><Lt><FieldRef Name='File_x0020_Size' /><Value Type='Number'>10000</Value></Lt></Query></Where>

    (Note : I have taken 1kb = 1000 bytes)

  4. Save your view and if required make it default.
| improve this answer | |
  • i will try this and let you back – adilahmed Aug 11 '15 at 5:57

Provided you have a View with the FileSize column displayed all the information is available in de ctx object.

You can process this with CSR or in a CEWP

Proof of concept code in F12 Dev Tools:

function countFileSize(min,max){//in bytes
    var total=0,
        var size=parseInt(row.File_x0020_Size);
        console.log('item ID',size,'item ID:',row.ID,row.FileLeafRef);
        if(size>min && size<max){
        } else {
            console.error('outside boundaries:',size,row.FileLeafRef);

    console.info('With boundaries:',min,max,' there are',count,'files','totalling',total,'bytes');
var average=countFileSize(0,100000);//bytes
console.info( 'average:',average,'bytes' );


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.