列表项具有2G附件时的Microsoft.SharePoint.Client.ServerException

时间:2016-01-13 21:13:04

标签: c# sharepoint office365 sharepoint-online sharepoint-clientobject

在SharePoint Online中,附件的大小限制为2G。但是,当我们尝试使用该列表项获取FieldValuesAsText属性时,我们遇到了以下异常:

未处理的异常:Microsoft.SharePoint.Client.ServerException:对于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()

我写了一个测试程序来重现这个错误,它在下面。由于错误发生在SharePoint Online服务器端,我该如何调试?我想在服务器端它使用Int32来转换文件大小(2G),这导致了这个错误。有没有办法解决这个问题?

此问题也可以通过以下方式重现:在一个驱动器中创建一个子文件夹,放置总大小> 2G的文件。由于“文件夹”实际上是一个项目,因此也会发生该异常。

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();
            }

        }
    }
}

0 个答案:

没有答案