Below is my C# code which I am using for connect SharePoint site.
When I try to access same SharePoint site from web page it's working fine and I able to access it But when I try to with below code I am getting error.
Microsoft.SharePoint.Client.IdcrlException: 'The sign-in name or password does not match one in the Microsoft account system.'
string targetSiteURL = "https://test.sharepoint.com/sites/SD/";
var login = "[email protected]";
var password = "password";
SecureString securePass = new SecureString();
foreach (char c in password.ToCharArray())
{
securePass.AppendChar(c);
}
//AuthenticationManager am = new AuthenticationManager();
//using (var cc = am.GetSharePointOnlineAuthenticatedContextTenant(targetSiteURL, login, securePass))
//{
// cc.ExecuteQuery();
// var count = cc.Web.Lists.Count;
//}
ClientContext context = new ClientContext(targetSiteURL);
context.RequestTimeout = -1;
context.AuthenticationMode = ClientAuthenticationMode.Default;
Web web = context.Web;
context.Credentials = new SharePointOnlineCredentials(login, securePass);
try
{
context.Load(web);
//context.ExecuteQueryAsync();
context.ExecuteQuery();
//context.ExecuteQueryAsync().Wait();
//var str = "true";
}
catch (Exception e)
{
var error = e.ToString();
}
Before asking question here, I spend a lot of time on it but i didn't get any solution. If any one know the solution of it then that is very helpful for me.
Notes- I am using below packages in C#.