Reputation: 1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
namespace Testmyproject
{
class Program
{
static void Main(string[] args)
{
string userName = "[email protected]";
Console.WriteLine("Enter Your Password Please ------- ");
SecureString password = GetPasswordOfYourSite();
// ClienContext - Get the context for the SharePoint Online Site
using (var clientContext = new
ClientContext("https://xqsnt.sharepoint.com/sites/mysite/"))
{
// SharePoint Online Credentials
clientContext.Credentials = new SharePointOnlineCredentials(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();
// Web properties - Display the Title and URL for the web
Console.WriteLine("Title: " + web.Title);
Console.WriteLine("URL: " + web.Url);
Console.WriteLine("Template: " + web.WebTemplate);
Console.ReadLine();
}
}
private static SecureString GetPasswordOfYourSite()
{
ConsoleKeyInfo info;
//Get the user's password as a SecureString
SecureString securePassword = new SecureString();
do
{
info = Console.ReadKey(true);
if (info.Key != ConsoleKey.Enter)
{
securePassword.AppendChar(info.KeyChar);
}
}
while (info.Key != ConsoleKey.Enter);
return securePassword;
}
}
}
If you are trying to run CSOM against SharePoint Online and gets the error below. All Contents are correct as like Site URL, Username and password. I need to display SharePoint Site Title, URL and Template but show Error at clientContext.ExecuteQuery(); enter image description here
Upvotes: 0
Views: 262
Reputation: 372
Please check your .NET Framework
version. Please change the version to 4.6 or later to resolve this issue. If you are using .NET Framework
under 4.6. You can add the following code to resolve this issue:
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
Hope it can help you. Thanks for your understanding.
Upvotes: 0