This SharePoint CSOM tutorial, we will discuss how to resolve the issue which comes in SharePoint 2013/2016 “the remote server returned an error 500 internal server error. sharepoint client object model”.
We were working in SharePoint 2016 client object in a console application where we received the below error:
An unhandled exception of type ‘System.Net.WebException’ occurred in System.dll
Additional information: The remote server returned an error: (500) Internal Server Error.
The remote server returned an error: (500) Internal Server Error
We wrote the below code to retrieve SharePoint site details using CSOM code.
private void GetSiteDetails()
{
using (ClientContext context = new ClientContext("http://mypc/sites/MySP2016SiteCollection/"))
{
context.AuthenticationMode = ClientAuthenticationMode.Default;
context.Credentials = new NetworkCredential(@"MYSP\Administrator", "Qwe@12345");
Web web = context.Web;
context.Load(web);
context.ExecuteQuery();
lblResult.Text = web.Title;
}
}
To connect to SharePoint 2016 site from the client-side object model, we need to provide credentials that we have provided in the below line which is perfect. Here http://mypc/sites/MySP2016SiteCollection/ was my SharePoint on-premise 2016 site.
context.Credentials = new NetworkCredential(@"MYSP\Administrator", "Qwe@12345");
But the error was coming because of the below line:
context.AuthenticationMode = ClientAuthenticationMode.Default;
So I have modified the CSOM code like below to resolve the issue.
private void GetSiteDetails()
{
using (ClientContext context = new ClientContext("http://mypc/sites/MySP2016SiteCollection/"))
{
context.Credentials = new NetworkCredential(@"MYSP\Administrator", "Qwe@12345");
Web web = context.Web;
context.Load(web);
context.ExecuteQuery();
lblResult.Text = web.Title;
}
}
Still if you are getting the above error, then try to change the account name, instead of using Administrator account. So you can pass like below:
context.Credentials = new NetworkCredential(@"MYSP\Bijay", "Qwe@12345");
Sometime you will get the below error also:
- Export to database failed. To export a list you must have a Microsoft SharePoint Foundation-compatible application error in SharePoint 2013
- Hide SharePoint List Title Column Programmatically using PnP CSOM
- How to export excel table to SharePoint List
- Bind SharePoint List items in dropdown list programmatically using CSOM
- Create Custom List and Fields in SharePoint Online using PnP Core CSOM Library
- Create Modern Team Site and Subsite using pnp csom programmatically in SharePoint Online
- The remote server returned an error (401) Unauthorized SharePoint Online/2016/2013 CSOM or PowerShell
I hope this will be helpful to resolve the remote server returned an error 500 internal server error which comes while working with the managed object model in SharePoint 2016/2013.
Hello Everyone!! I am Bhawana a SharePoint MVP and having about 10+ years of SharePoint experience as well as in .Net technologies. I have worked in all the versions of SharePoint from wss to Office 365. I have good exposure in Customization and Migration using Nintex, Metalogix tools. Now exploring more in SharePoint 2016 🙂 Hope here I can contribute and share my knowledge to the fullest. As I believe “There is no wealth like knowledge and no poverty like ignorance”