Sharepoint connection fails (Winforms, VB.Net)

LA RC 41 Reputation points

I did a small development where it is necessary to connect to a SharePoint list, the development works well with my user, but when testing with another user who has the same privileges on the site, it sends the following error message

"The sign-in name or password does not match one in the Microsoft Account System. "

I already tried with other users that the site are owners, but I get the same result. Can you help me see what is the error in the above?

This is my code.

Imports Microsoft.SharePoint.Client
Imports Microsoft.SharePoint
Imports System.Security
Imports System.Net

Public Class Form4

    Dim siteUrl As String = ""
    Dim context As New ClientContext(siteUrl)
    Dim web As Web

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

            Dim userNameSP As String = TextBox1.Text
            Dim password As String = TextBox2.Text
            Dim secureString As SecureString = New NetworkCredential("", password).SecurePassword

            Dim cred = New SharePointOnlineCredentials(userNameSP, secureString)
            Dim clientContext As New ClientContext(siteUrl)
            clientContext.Credentials = cred
            Dim web As Web = clientContext.Web
            Dim oWebsite As Web = clientContext.Web
            Dim collList As ListCollection = oWebsite.Lists

            Dim oList As List = collList.GetByTitle("Example Test")



            Dim query As CamlQuery = CamlQuery.CreateAllItemsQuery()

            query.ViewXml = "<View Scope='RecursiveAll'><Query><ViewFields><FieldRef Name='Category/></ViewFields></Query></View>"

            Dim AllItems As ListItemCollection = oList.GetItems(query)

            If AllItems.Count > 0 Then

                ... Do Something

            end if

        Catch ex As Exception
        End Try
    End Sub
End Class

Any idea?

Thank you in advance.

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,839 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,016 Reputation points

    Hi @LA RC ,

    Please make sure the username format like And check if the password of the user is incorrect or is expired.

    Besides, did you enable MFA on your tenant? If you enable MFA on the tenant, you would get this error. SharePoint CSOM would not work if MFA is enabled.

    For MFA tenant, you need to to OfficeDevPnP.Core.AuthenticationManager in CSOM

    Dim authauthManager As New AuthenticationManager()  
    Dim ctx As ClientContext = authauthManager.GetWebLoginClientContext(siteUrl)  

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    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