jithin
jithin

Reputation: 11

Exception when uploading files in SharePoint using a Windows application in C#

I want to upload files in SharePoint using a Windows application in C#.

using (ClientContext client = new ClientContext("https://jithin32.sharepoint.com/sites/demo"))
            {
                string passWd = "myPasssword";
                SecureString securePassWd = new SecureString();
                foreach (var c in passWd.ToCharArray())
                {
                    securePassWd.AppendChar(c);
                }
                client.Credentials = new SharePointOnlineCredentials("[email protected]", 
       securePassWd);
                var formLib = client.Web.Lists.GetByTitle("Documents");
                var fld1 = formLib.RootFolder.Folders.Add("case2");
                var fld2 = fld1.Folders.Add("10001");
                fld1.Update();
                fld2.Update();
                client.ExecuteQuery();
            }

but I got the following error:

Microsoft.SharePoint.Client.IdcrlException: 
'The sign-in name or password does not match one in the Microsoft account system.'

However, these credentials work fine when I manually type them into the SharePoint site.

Upvotes: 1

Views: 1974

Answers (1)

LZ_MSFT
LZ_MSFT

Reputation: 4228

If you enable Multi-Factor Authentication (MFA), you will get the this error message.

You need install the package using command below.

Install-Package SharePointPnPCoreOnline -Version 3.17.2001.2

Then using the code below to connect SharePoint Online.

var authManager = new AuthenticationManager();
var client = authManager.GetWebLoginClientContext("https://jithin32.sharepoint.com/sites/demo");

Reference: Office 365 : Connecting to SharePoint online site using CSOM when Multi-Factor Authentication (MFA) is enabled for the user

Upvotes: 2

Related Questions