1

Please see the code below. This is my initialization:

string siteUrl = "https://(*company domain*).sharepoint.com/sites/BankGuaranteeManagement/";
    string documentLibrary = "BG Docs";
    string fileName = VIEWSTATE_MAIN_FILE_NAME;
    string customerFolder = "Bank Guarantees";
    string userNameSP = "bgmfileuser@company.com";
    string passwordSP = "hs#29n#$";

This is the fileupload code:

        #region ConnectToSharePoint
        string serverRelativeURL = "";
        var securePassword = new SecureString();
        foreach (char c in Password)
        { securePassword.AppendChar(c); }
        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

        var onlineCredentials = new SharePointOnlineCredentials(Login, securePassword);
        #endregion
        #region Insert the data
       



        using (ClientContext clientContext = new ClientContext(siteUrl))
        {
            clientContext.Credentials = onlineCredentials;
            Web web = clientContext.Web;
            List libraryList = clientContext.Web.Lists.GetByTitle("Documents");
            Folder folder = libraryList.RootFolder;
            clientContext.Load(folder, f => f.ServerRelativeUrl);
            clientContext.ExecuteQuery();
            serverRelativeURL = folder.ServerRelativeUrl;

            System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, serverRelativeURL + "/" + System.IO.Path.GetFileName(filePath), fs, true);

        }

        
        #endregion
    }
    catch (Exception exp)
    {
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine(exp.Message + Environment.NewLine + exp.StackTrace);
    }

On clientContext.ExecuteQuery, I am getting the following error:

Exception

{"The sign-in name or password does not match one in the Microsoft account system."}

Some points worth mentioning:

  1. The ID being used in credentials has MFA disabled.

  2. The ID being used is part of the Active directory.

  3. I can login into portal.office.com using the same ID and password. So, no issues there.

  4. .Net version is 4.6

  5. Latest Sharepoint dll is installed and added.

I went through all materials on internet but cannot figure this ont out. Any help will be useful. Thanks.

  • Not sure this will fix your issue, but who knows: https://stackoverflow.com/questions/52707476/authentication-to-sharepoint-online-with-csom/52714695 – Kilazur Oct 29 '21 at 13:45
  • Setting LegacyAuthentication to true seems to be solution if exception is 401. But that is not the case here. – Wagish Singh Oct 29 '21 at 13:58

0 Answers0