0
votes

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!

1
Post the full exception, including the call stack. You can get it with Exception.ToString() or a simple Console.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.DefaultCredentialsPanagiotis Kanavos
BTW instead of trying code at random, read the docs. You need to pass the SharePoint site URL to the constructor. One SharePoint installation can have many web applications. Those applications in turn can have many independent sites.Panagiotis Kanavos
@PanagiotisKanavos I have added full exception message.Kishor T
did you check the URL? Did you remove the credentials, so you can connect with your own credentials? Can you connect to that site in the first place?Panagiotis Kanavos
@PanagiotisKanavos Yes, I had check with CredentialCache.DefaultCredentials ** and **CredentialCache.DefaultNetworkCredentials facing same issue still.Kishor T

1 Answers

1
votes

Check the follows:

1.Check all of your app pools, and check if the "SharePoint Web Services Root" stopped.

enter image description here

2.Check these SharePoint Services.

enter image description here

3.Check the IIS Admin Service.

enter image description here