Good morning, I´m currently stuck with an issue, I´m unable to find a solution for:
I want to connect to a on premise sharepoint 2016 using c#.
The library I use: Microsoft.SharePointOnline.CSOM Version 16.1.21909.1200 (most recent version)
My code:
using (ClientContext context = new ClientContext(sharepointUri))
{
context.Credentials = new NetworkCredential("firstname.lastname", "password");
Web web = context.Web;
context.Load(web);
context.ExecuteQuery();
This is however not working and returns an System.Net.WebException: 'The remote server returned an error: (401) Unauthorized.'
at the context.ExecuteQuery();
line.
I´ve seen numerous posts stating, that there is something wrong with the credentials, however when I login to the sharepoint using my browser, everything works fine.
I changed the Credentials to context.Credentials = new NetworkCredential(firstname.lastname", "password","domain");
-> correct domain
and its still not working.
SiteUrl is correct as well, when accessing it from the browser it works fine as well.
Any ideas what the problem could be?