3
votes

I am new to Sharepoint and Client Object model. I am stuck with a problem and not been able to fix the issue. I want to upload files more than 10 MB using Client Object Model in Sharepoint 2013. I get the following exception

The request message is too large. The server does not allow messages that are larger than 2097152 bytes.

I have tried everything. Here is the list of things that i did

1- Changed the settings in web.config file of my local web application

<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- In the powershell on my server ran the following commands and restarted the application in the IIS. Even restarted the whole IIS.

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

Here is my code :

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

    }

Note: I am able to upload small files.

2
Have you found any solution about it?Akash KC

2 Answers

2
votes

There are file size limit if you use the build-in upload function.

To upload a large file, please upload it with filestream.

Take a look at the article below:

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

0
votes

SharePoint allows you to configure this via Central Admin, I'd stick with that to make sure it makes all the appropriate changes for you. You need to have farm level permissions. Also in SharePoint 2013 you can have different file max limits for different file types so make sure your file type wasn't changed by anyone. Different Max based on File Types

Accessing SharePoint Webapp properties via central Admin