I have tried to implement on-premise SharePoint connecting from console as mentioned in following article, https://sharepoint.stackexchange.com/questions/205515/first-time-connecting-to-sharepoint-server-2013-from-console/205529?newreg=95ed260c717c4d9fb5fe4856a2daf71a
But things is that when execute program it throws internal exception(Code : 500). Unable to connect server :-(
Please check below code and let me know where/what I did wrong.
using (var clientContext = new ClientContext("http://customersupport/"))
{
try
{
Console.WriteLine("connecting on-premise sharepoint....");
clientContext.Credentials = new NetworkCredential(@"domain\username", "password");
// Get the SharePoint web
Web web = clientContext.Web;
// Load the Web properties
clientContext.Load(web);
// Execute the query to the server.
clientContext.ExecuteQuery();
Console.WriteLine("Conneciton done successfully");
}
catch (Exception exe)
{
//throws internal exception
Console.WriteLine(exe.Message);
}
}
below is full error message:
System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at ConnectSharepoint.SharePointOnPremise.Main(String[] args) in C:\Kishor\ac\2018\Test\ConnectSharepoint\SharePointOnPremise.cs:line 34
Thanks in advance!
Exception.ToString()
or a simpleConsole.WriteLine(exe)
. If you call the wrong URL though, you'll only get an error back. BTW you don't need to specify username/password if you want to connect with your current credentials. That means either don't set anything to the.Credentials
property or set it to CredentialCache.DefaultCredentials – Panagiotis Kanavos