SharePoint 2016 error 500 (internal server error)

Michel AL HAYEK 187 Reputation points
2021-03-13T13:19:53.183+00:00

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 https://www.vioreliftode.com/index.php/how-to-make-sharepoint-2016-not-fail-long-running-uploads-large-files/ 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(
                username,
                password,
                domain);



            using (var handler = new HttpClientHandler() { Credentials = credential, UseProxy = false })
            {
                using (var client = new HttpClient(handler))
                {
                    client.DefaultRequestHeaders.Accept.Clear();



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



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



                    client.DefaultRequestHeaders.Accept.Add(mediaType);



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



                    response.EnsureSuccessStatusCode();



                    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
    2021-03-15T03:41:29.107+00:00

    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:\testupload.zip";  
                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)  
            {  
                try  
                {  
                    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);  
                        Clientfolder.Update();  
                        SP.File uploadFile = Clientfolder.Files.Add(newFile);  
      
                        CContext.Load(DocumentLibrary);  
                        CContext.Load(uploadFile);  
                        CContext.ExecuteQuery();  
                        Console.ForegroundColor = ConsoleColor.Green;  
                        Console.WriteLine("The File has been uploaded" + Environment.NewLine + "FileUrl -->" + SiteUrl + "/" + DocLibrary + "/" + ClientSubFolder + "/" + Path.GetFileName(FileName));  
                    }  
      
                    #endregion  
                }  
                catch (Exception exp)  
                {  
                    Console.ForegroundColor = ConsoleColor.Red;  
                    Console.WriteLine(exp.Message + Environment.NewLine + exp.StackTrace);  
                }  
                finally  
                {  
                    Console.ReadLine();  
                }  
            }  
        }  
    }  
    

    Thanks
    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