SharePoint 2016 error 500 (internal server error)

Michel AL HAYEK 187 Reputation points

Hello Everyone, i am facing an issue with Sp16 when i upload many documents using rest API. when i upload many documents each one is 20mb i am receiving error 500 Internal server error.
any idea about this error and how to solve it?
i tried this but it didn't work for me. any other suggesstions?
my post request is below

public async Task<bool> Save(string requestUri, HttpContent content)
            var credential = new System.Net.NetworkCredential(

            using (var handler = new HttpClientHandler() { Credentials = credential, UseProxy = false })
                using (var client = new HttpClient(handler))

                    var mediaType = new MediaTypeWithQualityHeaderValue("application/json");

                    mediaType.Parameters.Add(new NameValueHeaderValue("odata", "nometadata"));


                    client.DefaultRequestHeaders.Add("X-RequestDigest", await this.GetRequestDigest());
                    client.DefaultRequestHeaders.Add("binaryStringRequestBody", "true");

                    string postUrl = this.siteUrl.EndsWith("/") ? $"{this.siteUrl}{requestUri}" : $"{this.siteUrl}/{requestUri}";
                    this.logger.LogDebug("Executing SharePointService.Save: PostUrl={0}.", postUrl);

                    HttpResponseMessage response = await client.PostAsync(postUrl, content);


                    this.logger.LogDebug("Executed SharePointService.Save: PostUrl={0}", postUrl);

                    return true;
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,594 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jerryzy 10,566 Reputation points

    Hi @Anonymous ,

    Suggest to use SharePoint CSOM library to upload files into SharePoint Library folder if you are using C# code, here is a code snippet for your reference:

    using System;  
    using System.IO;  
    using SP = Microsoft.SharePoint.Client;  
    namespace CSOM1  
        class ReadItem  
            static void Main(string[] args)  
                string SiteUrl = "http://sp2016/sites/dev/";  
                string DocumentLibrary = "UploadLibrary";  
                string FileName = @"C:\";  
                string CustomerFolder = "1564_dsfgsst";  
                string UserName = "TheUserName";  
                string Password = "ThePassword";  
                string Domain = "Contoso2016";  
                UploadFileToSharePoint(SiteUrl, DocumentLibrary, CustomerFolder, FileName, UserName, Password, Domain);  
            private static void UploadFileToSharePoint(string SiteUrl, string DocLibrary, string ClientSubFolder, string FileName, string Login, string Password, string Domain)  
                    using (SP.ClientContext CContext = new SP.ClientContext(SiteUrl))  
                        CContext.Credentials = new System.Net.NetworkCredential(Login, Password,Domain);  
                        SP.Web web = CContext.Web;  
                        SP.FileCreationInformation newFile = new SP.FileCreationInformation();  
                        byte[] FileContent = System.IO.File.ReadAllBytes(FileName);  
                        newFile.ContentStream = new MemoryStream(FileContent);  
                        newFile.Url = Path.GetFileName(FileName);  
                        SP.List DocumentLibrary = web.Lists.GetByTitle(DocLibrary);  
                        //SP.Folder folder = DocumentLibrary.RootFolder.Folders.GetByUrl(ClientSubFolder);  
                        SP.Folder Clientfolder = DocumentLibrary.RootFolder.Folders.Add(ClientSubFolder);  
                        SP.File uploadFile = Clientfolder.Files.Add(newFile);  
                        Console.ForegroundColor = ConsoleColor.Green;  
                        Console.WriteLine("The File has been uploaded" + Environment.NewLine + "FileUrl -->" + SiteUrl + "/" + DocLibrary + "/" + ClientSubFolder + "/" + Path.GetFileName(FileName));  
                catch (Exception exp)  
                    Console.ForegroundColor = ConsoleColor.Red;  
                    Console.WriteLine(exp.Message + Environment.NewLine + exp.StackTrace);  

    Best Regards

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful