1

In SharePoint online, the size limit of an attachment is 2G. However, when we tried to get FieldValuesAsText property with that list item, we got this exception:

Unhandled Exception: Microsoft.SharePoint.Client.ServerException: Value was either too large or too small for an Int32.

 at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream res
ponseStream)
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkString
Builder sb)
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
   at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
   at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()

I wrote a test program to reproduce this error, it is below. As the error is at the SharePoint Online server side, how do I debug this? I guess on the server side it use Int32 to convert the file size(2G), which leads to this error. Is there's a way to fix this?

Also this problem can be reproduced in this way: create a sub folder in the one drive, put files with total size>2G. As the 'Folder" is actually an item, that exception also occurs.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using System.Security;

namespace AttachmentLimit
{
    class Program
    {
        static void Main(string[] args)
        {
            string siteUrl = @"https://xxxinc-my.sharepoint.com";

            string userName = "xxx@xxxinc.onmicrosoft.com";

            string password = "xxxinc1234";

            SecureString secureString = new SecureString();
            password.ToList().ForEach(secureString.AppendChar);

            ClientContext ctx = new ClientContext(siteUrl);

            ctx.Credentials = new SharePointOnlineCredentials(userName, secureString);

            List docList = ctx.Web.Lists.GetByTitle("Documents");

            ctx.ExecuteQuery();

            CamlQuery query = CamlQuery.CreateAllItemsQuery(100); 
            ListItemCollection items = docList.GetItems(query);

            // Retrieve all items in the ListItemCollection from List.GetItems(Query). 
            ctx.Load(items);
            ctx.ExecuteQuery();

            foreach (ListItem listItem in items)
            {
                ctx.Load(listItem);
                ctx.Load(listItem, li => li.DisplayName, li => li.Id);
                ctx.ExecuteQuery();
                Console.WriteLine(listItem.DisplayName + listItem.Id);

                //ServerException when file size is 2G
                FieldStringValues fieldStringValuesText = listItem.FieldValuesAsText;
                FieldStringValues fieldStringValuesHtml = listItem.FieldValuesAsHtml;
                ctx.Load(fieldStringValuesText);
                ctx.Load(fieldStringValuesHtml);
                ctx.ExecuteQuery();
            }

        }
    }
}
Matt
  • 6,010
  • 25
  • 36

0 Answers0