I have to report weekly on the number of documents being stored in one of our document libraries. My manager wants the headline figures:

  • Total number of files stored
  • Average file size
  • Total file size

Until today I have been able to provide these with a custom view. When I tried to run the report this morning I got an error with a correlation ID. I tracked this in the error log and found the following error:

System.Data.SqlClient.SqlException (0x80131904): Arithmetic overflow error converting expression to data type int.

I've figured out that the total file size has gone over 2,147,483,647 bytes. Is there a way that I can recast the file size field as a bigint or is there a better way to report these figures?

  • The Int limitation is a SharePoint Application limitation, that code originates from (very) old SharePoint versions and was never adapted to handle larger values. It is not a database (field) restriction. – Danny '365CSI' Engelman Nov 6 '15 at 10:54

Provided you have a ListView with all files displayed, and the File Size is displayed in the View,
you can execute client-side code from the Developer Console (or a CEWP, or CSR)

function countFileSize(min,max){//in bytes
    var total=0,count=0;
        var size=parseInt(row.File_x0020_Size);//needs to be displayed in the View!
        //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 byte boundaries:',min,max,' there are',count,'files','totalling',total,'bytes. Average:',~~(total/count),'bytes per file');
  • This code works brilliantly on small lists but the list I am working with contains 20,000+ documents. Trying to display this many in a single view has locked up my IE multiple times in the last hour. – Burgi Nov 6 '15 at 9:58
  • Yes, in order for this to work all items (or all you want to count) need to be displayed on one page. Anything over the (Microsoft recommened) 5000 listitems will not perform well. – Danny '365CSI' Engelman Nov 6 '15 at 10:51
  • You might be better of doing this (same concept) with PowerShell. – Danny '365CSI' Engelman Nov 6 '15 at 10:55
  • I'm not very familiar with PowerShell, I'll have a look at it. Thanks for the tip. – Burgi Nov 6 '15 at 11:05
  • Unless you add over 5000 documents a week, a weekly delta report can be created with a View filtered on Created > [Today]-7 – Danny '365CSI' Engelman Nov 6 '15 at 11:12

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.