[使用c#中的Windows应用程序在SharePoint中上传文件

问题描述 投票:0回答:1

我想使用c#中的Windows应用程序在SharePoint中上载文件。

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();
            }

但出现以下错误:

Microsoft.SharePoint.Client.IdcrlException: 
'The sign-in name or password does not match one in the Microsoft account system.'
c# sharepoint-2010
1个回答
0
投票

如果启用多重身份验证(MFA),则会收到此错误消息。

您需要使用下面的命令安装软件包。

Install-Package SharePointPnPCoreOnline -Version 3.17.2001.2

然后使用下面的代码连接SharePoint Online。

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

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

© www.soinside.com 2019 - 2024. All rights reserved.