Sharepoint 2013客户端对象模型文件超过2 Mb异常

时间:2013-11-19 16:30:20

标签: sharepoint sharepoint-2010 sharepoint-2013 client-object-model sharepoint-clientobject

我是Sharepoint和Client Object模型的新手。我遇到了问题而无法解决问题。我想在Sharepoint 2013中使用客户端对象模型上传超过10 MB的文件。我得到以下异常

  

请求消息太大。服务器不允许消息   大于2097152字节。

我已经尝试了一切。这是我做的事情清单

1-更改了本地Web应用程序的web.config文件中的设置

<system.web>
<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="2147483647" requestLengthDiskThreshold="2147483647" executionTimeout="18000"/> </system.web>

<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>

2-在我的服务器上的powershell中运行以下命令并在IIS中重新启动应用程序。甚至重新启动了整个IIS。

$ws = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$ws.ClientRequestServiceSettings.MaxReceivedMessageSize = 2147483647
$ws.Update()

这是我的代码:

private void UploadDataToSharepointTest(List<UploadData> pDataObjList)
    {
        string lServerUrl = @"http://xxxxxxx:2000/";
        string lFolderName = DateTime.Now.ToString(@"yyyyMMddHHmmss");


        ClientContext context = new ClientContext(lServerUrl);
        context.AuthenticationMode = ClientAuthenticationMode.Default;
        context.Credentials = new System.Net.NetworkCredential("user", "password", "domain");        

        Web web = context.Web;
        List docs = web.Lists.GetByTitle("ABC");
        Folder lNewFolder = web.Folders.Add(lServerUrl + "ABC/" + lFolderName + "/");
        docs.Update();

        int fileIndex = 1;
        foreach (var item in pDataObjList)
        {
            FileCreationInformation newFile = new FileCreationInformation();
            newFile.Content = System.IO.File.ReadAllBytes(item.CompleteFilePath);
            newFile.Url = fileIndex.ToString() + "-" + item.fileName;
            fileIndex++;

            Microsoft.SharePoint.Client.File uploadFile = lNewFolder.Files.Add(newFile);

            context.Load(uploadFile);
            context.ExecuteQuery();

            Dictionary<string, string> metadata = new Dictionary<string, string>();
            metadata.Add("Comments", item.comments);
            metadata.Add("Plan_x0020_Size", item.planSize);
            metadata.Add("Density", item.density);
            metadata.Add("First_x0020_Name", txtFirstName.Text.Trim());
            metadata.Add("Last_x0020_Name", txtLastName.Text.Trim());
            metadata.Add("Company", txtCompany.Text.Trim());
            metadata.Add("Contact", txtContact.Text.Trim());
            metadata.Add("Additional_x0020_Comments", txtAdditionalComments.Text.Trim());

            Microsoft.SharePoint.Client.ListItem items = uploadFile.ListItemAllFields;
            context.Load(items);
            context.ExecuteQuery();

            foreach (KeyValuePair<string, string> metadataitem in metadata)
            {
                items[metadataitem.Key.ToString()] = metadataitem.Value.ToString();
            }

            items.Update();
            context.ExecuteQuery();
        }

    }

注意:我可以上传小文件。

2 个答案:

答案 0 :(得分:2)

如果使用内置上传功能,则存在文件大小限制。

要上传大文件,请上传文件流。

看一下下面的文章:

http://blogs.msdn.com/b/sridhara/archive/2010/03/12/uploading-files-using-client-object-model-in-sharepoint-2010.aspx

答案 1 :(得分:0)

SharePoint允许您通过中央管理员进行配置,我会坚持使用它来确保它为您做出所有适当的更改。您需要具有服务器场级别权限。此外,在SharePoint 2013中,您可以为不同的文件类型设置不同的文件最大限制,因此请确保您的文件类型未被任何人更改。 Different Max based on File Types

Accessing SharePoint Webapp properties via central Admin