Forum Discussion

spaieszambiacom's avatar
spaieszambiacom
Copper Contributor
Oct 04, 2022
Solved

Sharepoint online CSOM error

Hello, 

 

I've been trying this simple CSOM code:

string siteCollectionUrl = "https://ieszambia.sharepoint.com/"; string userName = "mailto:email address removed for privacy reasons"; string password = "Put00745"; // Namespace: Microsoft.SharePoint.Client ClientContext ctx = new ClientContext(siteCollectionUrl); // Namespace: http://system.security/ SecureString secureString = new SecureString(); password.ToList().ForEach(secureString.AppendChar); // Namespace: Microsoft.SharePoint.Client ctx.Credentials = new SharePointOnlineCredentials(userName, secureString); // Namespace: Microsoft.SharePoint.Client Site site = http://ctx.site/; ctx.Load(site); ctx.ExecuteQuery(); return View(site.Url.ToString());

 

 

and I keep getting the following error: the sign-in name or password does not match one in the microsoft account. 

 

Even though I can log into sharepoint using those same credentials. ITs driving me crazy, what am I doing wrong? 

  • SvenSieverding's avatar
    SvenSieverding
    Oct 04, 2022

    spaieszambiacom 

    Mhm.... i normally use the "PnP.Framework" Library and this code

    SecureString securePassword = new NetworkCredential("", password).SecurePassword;

    PnP.Framework.AuthenticationManager auth = new PnP.Framework.AuthenticationManager(username,securePassword);
    ClientContext ctx = auth.GetContext(siteUrl);


4 Replies

Resources