SharePoint Online CSOM

Pratap Bangosavi 41 Reputation points
2023-01-10T08:46:17.83+00:00

//Error show on clientContext.ExecuteQuery() 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 = "******@xqsnt.onmicrosoft.com"; 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; } } }

277824-image.png

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft 365 and Office | SharePoint Server | Development
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,481 Reputation points Microsoft External Staff
    2023-01-11T01:53:21.943+00:00

    Hi @Pratap Bangosavi The issue related to default TLS settings of a web request. Please check your .Net Framework version in properties 278067-image.png You can change the version to 4.6 or later version to fix the issue. If you are using .Net Framework under 4.6. You can add following code to use tls12

    ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
    

    Here is the result of your code 278028-image.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.